﻿using System;
using System.Text;
using System.Security;
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

using ClassID = System.Runtime.InteropServices.GuidAttribute;
using System.Runtime.CompilerServices;
using System.Reflection;

//ProtocolHandlerOnResponse
namespace PickGold.Forms
{
	/// <summary>
	/// 使用户可以在窗体中导航网页。
	/// </summary>
	[ComVisible(true)]
	[ClassInterface(ClassInterfaceType.AutoDispatch)]
	public class InternetExplorer : WebBrowser
	{
		//CoInternetSetFeatureEnabled 屏蔽声音似乎可用这个。

		#region internal class or interface

		#region enum OLECMDID

		public enum OLECMDID
		{
			OPEN = 1,
			NEW = 2,
			SAVE = 3,
			SAVEAS = 4,
			SAVECOPYAS = 5,
			PRINT = 6,
			PRINTPREVIEW = 7,
			PAGESETUP = 8,
			SPELL = 9,
			PROPERTIES = 10,
			CUT = 11,
			COPY = 12,
			PASTE = 13,
			PASTESPECIAL = 14,
			UNDO = 15,
			REDO = 16,
			SELECTALL = 17,
			CLEARSELECTION = 18,
			ZOOM = 19,
			GETZOOMRANGE = 20,
			UPDATECOMMANDS = 21,
			REFRESH = 22,
			STOP = 23,
			HIDETOOLBARS = 24,
			SETPROGRESSMAX = 25,
			SETPROGRESSPOS = 26,
			SETPROGRESSTEXT = 27,
			SETTITLE = 28,
			SETDOWNLOADSTATE = 29,
			STOPDOWNLOAD = 30,
			ONTOOLBARACTIVATED = 31,
			FIND = 32,
			DELETE = 33,
			HTTPEQUIV = 34,
			HTTPEQUIV_DONE = 35,
			ENABLE_INTERACTION = 36,
			ONUNLOAD = 37,
			PROPERTYBAG2 = 38,
			PREREFRESH = 39,
			SHOWSCRIPTERROR = 40,
			SHOWMESSAGE = 41,
			SHOWFIND = 42,
			SHOWPAGESETUP = 43,
			SHOWPRINT = 44,
			CLOSE = 45,
			ALLOWUILESSSAVEAS = 46,
			DONTDOWNLOADCSS = 47,
			UPDATEPAGESTATUS = 48,
			PRINT2 = 49,
			PRINTPREVIEW2 = 50,
			SETPRINTTEMPLATE = 51,
			GETPRINTTEMPLATE = 52,
			PAGEACTIONBLOCKED = 55,
			PAGEACTIONUIQUERY = 56,
			FOCUSVIEWCONTROLS = 57,
			FOCUSVIEWCONTROLSQUERY = 58,
			SHOWPAGEACTIONMENU = 59,
			ADDTRAVELENTRY = 60,
			UPDATETRAVELENTRY = 61,
			UPDATEBACKFORWARDSTATE = 62,
			OPTICAL_ZOOM = 63,
			OPTICAL_GETZOOMRANGE = 64,
			WINDOWSTATECHANGED = 65,
			ACTIVEXINSTALLSCOPE = 66,
			UPDATETRAVELENTRY_DATARECOVERY = 67,
		}

		#endregion

		#region enum OLECMDEXECOPT

		public enum OLECMDEXECOPT
		{
			DODEFAULT = 0,
			PROMPTUSER = 1,
			DONTPROMPTUSER = 2,
			SHOWHELP = 3,
		}

		#endregion

		#region enum tagREADYSTATE

		enum tagREADYSTATE
		{
			UNINITIALIZED = 0,
			LOADING = 1,
			LOADED = 2,
			INTERACTIVE = 3,
			COMPLETE = 4,
		}

		#endregion

		#region enum OLECMDF

		public enum OLECMDF
		{
			SUPPORTED = 1,
			ENABLED = 2,
			LATCHED = 4,
			NINCHED = 8,
			INVISIBLE = 16,
			DEFHIDEONCTXTMENU = 32,
		}

		#endregion

		#region class COMRECT

		[StructLayout(LayoutKind.Sequential)]
		class COMRECT
		{
			public int left;
			public int top;
			public int right;
			public int bottom;

			public COMRECT()
			{
				this.left = 0;
				this.top = 0;
				this.right = 0;
				this.bottom = 0;
			}

			public COMRECT(Rectangle r)
			{
				this.left = r.X;
				this.top = r.Y;
				this.right = r.Right;
				this.bottom = r.Bottom;
			}

			public COMRECT(int left, int top, int right, int bottom)
			{
				this.left = left;
				this.top = top;
				this.right = right;
				this.bottom = bottom;
			}

			public static COMRECT FromXYWH(int x, int y, int width, int height)
			{
				return new COMRECT(x, y, x + width, y + height);
			}

			public override string ToString()
			{
				return string.Concat(new object[] { "Left = ", this.left, " Top ", this.top, " Right = ", this.right, " Bottom = ", this.bottom });
			}
		}

		#endregion

		#region class tagDVTARGETDEVICE

		[StructLayout(LayoutKind.Sequential)]
		class tagDVTARGETDEVICE
		{
			[MarshalAs(UnmanagedType.U4)]
			public int tdSize;
			[MarshalAs(UnmanagedType.U2)]
			public short tdDriverNameOffset;
			[MarshalAs(UnmanagedType.U2)]
			public short tdDeviceNameOffset;
			[MarshalAs(UnmanagedType.U2)]
			public short tdPortNameOffset;
			[MarshalAs(UnmanagedType.U2)]
			public short tdExtDevmodeOffset;
		}

		#endregion

		#region class tagLOGPALETTE

		[StructLayout(LayoutKind.Sequential)]
		class tagLOGPALETTE
		{
			[MarshalAs(UnmanagedType.U2)]
			public short palVersion;
			[MarshalAs(UnmanagedType.U2)]
			public short palNumEntries;
		}

		#endregion

		#region interface IViewObject

		[ComImport]
		[SuppressUnmanagedCodeSecurity]
		[ClassID("0000010d-0000-0000-C000-000000000046")]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		interface IViewObject
		{
			[PreserveSig]
			int Draw([In][MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] tagDVTARGETDEVICE ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [In] COMRECT lprcBounds, [In] COMRECT lprcWBounds, IntPtr pfnContinue, [In] int dwContinue);
			[PreserveSig]
			int GetColorSet([In][MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] tagDVTARGETDEVICE ptd, IntPtr hicTargetDev, [Out] tagLOGPALETTE ppColorSet);
			[PreserveSig]
			int Freeze([In][MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [Out] IntPtr pdwFreeze);
			[PreserveSig]
			int Unfreeze([In][MarshalAs(UnmanagedType.U4)] int dwFreeze);
			void SetAdvise([In][MarshalAs(UnmanagedType.U4)] int aspects, [In][MarshalAs(UnmanagedType.U4)] int advf, [In][MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink);
			void GetAdvise([In][Out][MarshalAs(UnmanagedType.LPArray)] int[] paspects, [In][Out][MarshalAs(UnmanagedType.LPArray)] int[] advf, [In][Out][MarshalAs(UnmanagedType.LPArray)] IAdviseSink[] pAdvSink);
		}

		#endregion

		#region DWebBrowserEvents2

		[ComImport]
		[SuppressUnmanagedCodeSecurity]
		[TypeLibType(TypeLibTypeFlags.FHidden)]
		[ClassID("34A715A0-6587-11D0-924A-0020AFC7AC4D")]
		[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
		interface DWebBrowserEvents2
		{
			//[DispId(250)]
			//void BeforeNavigate2([In][MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In][Out] ref object URL, [In][Out] ref object flags, [In][Out] ref object targetFrameName, [In][Out] ref object postData, [In][Out] ref object headers, [In][Out] ref bool cancel);

			//[DispId(273)]
			//void NewWindow3([In][Out][MarshalAs(UnmanagedType.IDispatch)] ref object pDisp, [In][Out] ref bool cancel, [In][Out] ref object flags, [In][Out] ref object URLContext, [In][Out] ref object URL);

			//[DispId(271)]
			//void NavigateError([In][Out][MarshalAs(UnmanagedType.IDispatch)] ref object pDisp, [In][Out] ref object URL, [In][Out] ref object frame, [In][Out] ref object statusCode, [In][Out] ref bool cancel);

			[DispId(0x66)]
			void StatusTextChange([MarshalAs(UnmanagedType.BStr)] string Text);
			[DispId(0x6c)]
			void ProgressChange(int Progress, int ProgressMax);
			[DispId(0x69)]
			void CommandStateChange(int Command, [MarshalAs(UnmanagedType.VariantBool)] bool Enable);
			[DispId(0x6a)]
			void DownloadBegin();
			[DispId(0x68)]
			void DownloadComplete();
			[DispId(0x71)]
			void TitleChange([MarshalAs(UnmanagedType.BStr)] string Text);
			[DispId(0x70)]
			void PropertyChange([MarshalAs(UnmanagedType.BStr)] string szProperty);
			[DispId(0xfa)]
			void BeforeNavigate2([MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL, [In] ref object Flags, [In] ref object TargetFrameName, [In] ref object PostData, [In] ref object Headers, [In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel);
			[DispId(0xfb)]
			void NewWindow2([In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object ppDisp, [In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel);
			[DispId(0xfc)]
			void NavigateComplete2([MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL);
			[DispId(0x103)]
			void DocumentComplete([MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL);
			[DispId(0xfd)]
			void OnQuit();
			[DispId(0xfe)]
			void OnVisible([MarshalAs(UnmanagedType.VariantBool)] bool Visible);
			[DispId(0xff)]
			void OnToolBar([MarshalAs(UnmanagedType.VariantBool)] bool ToolBar);
			[DispId(0x100)]
			void OnMenuBar([MarshalAs(UnmanagedType.VariantBool)] bool MenuBar);
			[DispId(0x101)]
			void OnStatusBar([MarshalAs(UnmanagedType.VariantBool)] bool StatusBar);
			[DispId(0x102)]
			void OnFullScreen([MarshalAs(UnmanagedType.VariantBool)] bool FullScreen);
			[DispId(0x104)]
			void OnTheaterMode([MarshalAs(UnmanagedType.VariantBool)] bool TheaterMode);
			[DispId(0x106)]
			void WindowSetResizable([MarshalAs(UnmanagedType.VariantBool)] bool Resizable);
			[DispId(0x108)]
			void WindowSetLeft(int Left);
			[DispId(0x109)]
			void WindowSetTop(int Top);
			[DispId(0x10a)]
			void WindowSetWidth(int Width);
			[DispId(0x10b)]
			void WindowSetHeight(int Height);
			[DispId(0x107)]
			void WindowClosing([MarshalAs(UnmanagedType.VariantBool)] bool IsChildWindow, [In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel);
			[DispId(0x10c)]
			void ClientToHostWindow([In, Out] ref int CX, [In, Out] ref int CY);
			[DispId(0x10d)]
			void SetSecureLockIcon(int SecureLockIcon);
			[DispId(0x10e)]
			void FileDownload([In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel);
			[DispId(0x10f)]
			void NavigateError([MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object URL, [In] ref object Frame, [In] ref object StatusCode, [In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel);
			[DispId(0xe1)]
			void PrintTemplateInstantiation([MarshalAs(UnmanagedType.IDispatch)] object pDisp);
			[DispId(0xe2)]
			void PrintTemplateTeardown([MarshalAs(UnmanagedType.IDispatch)] object pDisp);
			[DispId(0xe3)]
			void UpdatePageStatus([MarshalAs(UnmanagedType.IDispatch)] object pDisp, [In] ref object nPage, [In] ref object fDone);
			[DispId(0x110)]
			void PrivacyImpactedStateChange([MarshalAs(UnmanagedType.VariantBool)] bool bImpacted);
			[DispId(0x111)]
			void NewWindow3([In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object ppDisp, [In, Out, MarshalAs(UnmanagedType.VariantBool)] ref bool Cancel, uint dwFlags, [MarshalAs(UnmanagedType.BStr)] string bstrUrlContext, [MarshalAs(UnmanagedType.BStr)] string bstrUrl);
		}

		class DWebBrowserEvents2Class : StandardOleMarshalObject, DWebBrowserEvents2
		{
			private InternetExplorer _IE;

			public DWebBrowserEvents2Class(InternetExplorer ie)
			{
				this._IE = ie;
			}
			/*
			public void BeforeNavigate2(object pDisp, ref object URL, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(URL as string, targetFrameName as string, 0);
				e.Flags = flags;
				e.PostData = postData;
				e.Headers = headers;
				this._IE.OnBeforeNavigate(e);
				flags = e.Flags;
				postData = e.PostData;
				headers = e.Headers;
				cancel = e.Cancel;
			}

			public void NewWindow3(ref object pDisp, ref bool cancel, ref object flags, ref object URLContext, ref object URL)
			{
				var e = new UrlNavigateEventArgs(URL as string, null, 0);
				e.Flags = flags;
				e.UrlContext = URLContext;
				this._IE.OnBeforeNewWindow(e);
				flags = e.Flags;
				URLContext = e.UrlContext;
				cancel = e.Cancel;
				if (e.Target == null)
					return;

				var wb = e.Target.ActiveXInstance as IWebBrowser2;
				if (wb == null)
					return;

				pDisp = wb.Application;
				//var frm = new Form();
				//var ie = new InternetExplorer();
				//frm.Controls.Add(ie);
				//ie.Navigate(string.Empty);
				//ie.Dock = DockStyle.Fill;
				//ie._WebBrowser2.RegisterAsBrowser = true;
				//frm.Show();
				//pDisp = ie._WebBrowser2.Application;
			}

			public void NavigateError(ref object pDisp, ref object URL, ref object frame, ref object statusCode, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(URL as string, frame as string, (int)statusCode);
				this._IE.OnNavigateError(e);
				cancel = e.Cancel;
			}
			*/

			#region DWebBrowserEvents2 成员

			public void StatusTextChange(string text)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, text);
				this._IE.OnStatusTextChange(e);
			}

			public void ProgressChange(int progress, int progressMax)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, new int[] { progress, progressMax });
				this._IE.OnProgressChange(e);
			}

			public void CommandStateChange(int command, bool enable)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, new int[] { command, enable ? 1 : 0 });
				this._IE.OnCommandStateChange(e);
			}

			public void DownloadBegin()
			{
				this._IE.OnDownloadBegin(EventArgs.Empty);
			}

			public void DownloadComplete()
			{
				this._IE.OnDownloadComplete(EventArgs.Empty);
			}

			public void TitleChange(string text)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, text);
				this._IE.OnTitleChange(e);
			}

			public void PropertyChange(string property)
			{
				var e = new PropertyChangedEventArgs(property);
				this._IE.OnPropertyChange(e);
			}

			public void BeforeNavigate2(object pDisp, ref object URL, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(URL as string, targetFrameName as string, 0);
				e.Flags = flags;
				e.PostData = postData as string;
				e.Headers = headers as string;
				this._IE.OnBeforeNavigate(e);
				flags = e.Flags;
				postData = e.PostData;
				headers = e.Headers;
				cancel = e.Cancel;
			}

			public void NewWindow2(ref object pDisp, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(null, null, 0);
				this._IE.OnNewWindow2(e);
				cancel = e.Cancel;
			}

			public void NavigateComplete2(object pDisp, ref object URL)
			{
				var e = new UrlNavigateEventArgs(URL as string, null, 0);
				this._IE.OnNavigateComplete(e);
				URL = e.Url;
			}

			public void DocumentComplete(object pDisp, ref object URL)
			{
				var e = new UrlNavigateEventArgs(URL as string, null, 0);
				this._IE.OnDocumentComplete(e);
				URL = e.Url;
			}

			public void OnQuit()
			{
				this._IE.OnQuit(EventArgs.Empty);
			}

			public void OnVisible(bool visible)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, visible);
				this._IE.OnDisplay(e);
			}

			public void OnToolBar(bool toolBar)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, toolBar);
				this._IE.OnToolBar(e);
			}

			public void OnMenuBar(bool menuBar)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, menuBar);
				this._IE.OnMenuBar(e);
			}

			public void OnStatusBar(bool statusBar)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, statusBar);
				this._IE.OnStatusBar(e);
			}

			public void OnFullScreen(bool fullScreen)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, fullScreen);
				this._IE.OnFullScreen(e);
			}

			public void OnTheaterMode(bool theaterMode)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, theaterMode);
				this._IE.OnTheaterMode(e);
			}

			public void WindowSetResizable(bool resizable)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, resizable);
				this._IE.OnSetResizable(e);
			}

			public void WindowSetLeft(int left)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, left);
				this._IE.OnSetLeft(e);
			}

			public void WindowSetTop(int top)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, top);
				this._IE.OnSetTop(e);
			}

			public void WindowSetWidth(int width)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, width);
				this._IE.OnSetWidth(e);
			}

			public void WindowSetHeight(int height)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, height);
				this._IE.OnSetHeight(e);
			}

			public void WindowClosing(bool isChildWindow, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, isChildWindow);
				e.Flags = isChildWindow;
				e.Cancel = cancel;
				this._IE.OnClosing(e);
				cancel = e.Cancel;
			}

			public void ClientToHostWindow(ref int CX, ref int CY)
			{
				var point = new Point(CX, CY);
				var e = new UrlNavigateEventArgs(null, null, 0, point);
				this._IE.OnClientToHostWindow(e);
				var data = e.Data;
				if (data is Point)
				{
					point = (Point)data;
					CX = point.X;
					CY = point.Y;
				}
			}

			public void SetSecureLockIcon(int secureLockIcon)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, secureLockIcon);
				this._IE.OnSetSecureLockIcon(e);
			}

			public void FileDownload(ref bool cancel)
			{
				var e = new CancelEventArgs(cancel);
				e.Cancel = cancel;
				this._IE.OnDownloadFile(e);
				cancel = e.Cancel;
			}

			public void NavigateError(object pDisp, ref object URL, ref object frame, ref object statusCode, ref bool cancel)
			{
				var e = new UrlNavigateEventArgs(URL as string, frame as string, (int)statusCode);
				this._IE.OnNavigateError(e);
				cancel = e.Cancel;
			}

			public void PrintTemplateInstantiation(object pDisp)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, pDisp);
				this._IE.OnPrintTemplateInstantiation(e);
			}

			public void PrintTemplateTeardown(object pDisp)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, pDisp);
				this._IE.OnPrintTemplateTeardown(e);
			}

			public void UpdatePageStatus(object pDisp, ref object nPage, ref object fDone)
			{
				var e = new UrlNavigateEventArgs(null, null, 0);
				e.Flags = nPage;
				e.Data = fDone;
				this._IE.OnUpdatePageStatus(e);
				nPage = e.Flags;
				fDone = e.Data;
			}

			public void PrivacyImpactedStateChange(bool impacted)
			{
				var e = new UrlNavigateEventArgs(null, null, 0, impacted);
				this._IE.OnPrivacyImpactedStateChange(e);
			}

			public void NewWindow3(ref object pDisp, ref bool cancel, uint flags, string URLContext, string URL)
			{
				var e = new UrlNavigateEventArgs(URL as string, null, 0);
				e.Flags = flags;
				e.UrlContext = URLContext;
				this._IE.OnBeforeNewWindow(e);
				flags = object.Equals(e.Flags, true) ? 1U : 0U;
				URLContext = e.UrlContext as string;
				cancel = e.Cancel;
				if (e.Target == null)
					return;

				var wb = e.Target.ActiveXInstance as IWebBrowser2;
				if (wb == null)
					return;

				pDisp = wb.Application;
				//var frm = new Form();
				//var ie = new InternetExplorer();
				//frm.Controls.Add(ie);
				//ie.Navigate(string.Empty);
				//ie.Dock = DockStyle.Fill;
				//ie._WebBrowser2.RegisterAsBrowser = true;
				//frm.Show();
				//pDisp = ie._WebBrowser2.Application;
			}

			#endregion
		}

		#endregion

		#region public interface IWebBrowser2

		[ComImport]
		//[TypeLibType(4176)]
		[SuppressUnmanagedCodeSecurity]
		[Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E")]
		//[TypeLibType(TypeLibTypeFlags.FOleAutomation | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden)]
		[TypeLibType(TypeLibTypeFlags.FOleAutomation | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden | TypeLibTypeFlags.FDispatchable)]
		public interface IWebBrowser2// : IWebBrowserApp
		{
			#region !-0 :IWebBrowserApp

			/*
			[DispId(555)]
			bool AddressBar { get; set; }
			[DispId(200)]
			object Application { get; }
			[DispId(212)]
			bool Busy { get; }
			[DispId(202)]
			object Container { get; }
			[DispId(203)]
			object Document { get; }
			[DispId(400)]
			string FullName { get; }
			[DispId(407)]
			bool FullScreen { get; set; }
			[DispId(209)]
			int Height { get; set; }
			[DispId(-515)]
			int HWND { get; }
			[DispId(206)]
			int Left { get; set; }
			[DispId(210)]
			string LocationName { get; }
			[DispId(211)]
			string LocationURL { get; }
			[DispId(406)]
			bool MenuBar { get; set; }
			[DispId(0)]
			string Name { get; }
			[DispId(550)]
			bool Offline { get; set; }
			[DispId(201)]
			object Parent { get; }
			[DispId(401)]
			string Path { get; }
			[DispId(-525)]
			tagREADYSTATE ReadyState { get; }
			[DispId(552)]
			bool RegisterAsBrowser { get; set; }
			[DispId(553)]
			bool RegisterAsDropTarget { get; set; }
			[DispId(556)]
			bool Resizable { get; set; }
			[DispId(551)]
			bool Silent { get; set; }
			[DispId(403)]
			bool StatusBar { get; set; }
			[DispId(404)]
			string StatusText { get; set; }
			[DispId(554)]
			bool TheaterMode { get; set; }
			[DispId(405)]
			int ToolBar { get; set; }
			[DispId(207)]
			int Top { get; set; }
			[DispId(204)]
			bool TopLevelContainer { get; }
			[DispId(205)]
			string Type { get; }
			[DispId(402)]
			bool Visible { get; set; }
			[DispId(208)]
			int Width { get; set; }

			[DispId(301)]
			void ClientToWindow(ref int pcx, ref int pcy);
			[DispId(502)]
			void ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, ref object pvaIn, ref object pvaOut);
			[DispId(303)]
			object GetProperty(string Property);
			[DispId(100)]
			void GoBack();
			[DispId(101)]
			void GoForward();
			[DispId(102)]
			void GoHome();
			[DispId(103)]
			void GoSearch();
			[DispId(104)]
			void Navigate(string URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers);
			[DispId(500)]
			void Navigate2(ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers);
			[DispId(302)]
			void PutProperty(string Property, object vtValue);
			[DispId(501)]
			OLECMDF QueryStatusWB(OLECMDID cmdID);
			[DispId(300)]
			void Quit();
			[DispId(-550)]
			void Refresh();
			[DispId(105)]
			void Refresh2(ref object Level);
			[DispId(503)]
			void ShowBrowserBar(ref object pvaClsid, ref object pvarShow, ref object pvarSize);
			[DispId(106)]
			void Stop();
			*/
			#endregion

			#region !

			[DispId(100)]
			void GoBack();
			[DispId(0x65)]
			void GoForward();
			[DispId(0x66)]
			void GoHome();
			[DispId(0x67)]
			void GoSearch();
			[DispId(0x68)]
			void Navigate([In] string Url, [In] ref object flags, [In] ref object targetFrameName, [In] ref object postData, [In] ref object headers);
			[DispId(-550)]
			void Refresh();
			[DispId(0x69)]
			void Refresh2([In] ref object level);
			[DispId(0x6a)]
			void Stop();
			[DispId(200)]
			object Application { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
			[DispId(0xc9)]
			object Parent { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
			[DispId(0xca)]
			object Container { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
			[DispId(0xcb)]
			object Document { [return: MarshalAs(UnmanagedType.IDispatch)] get; }
			[DispId(0xcc)]
			bool TopLevelContainer { get; }
			[DispId(0xcd)]
			string Type { get; }
			[DispId(0xce)]
			int Left { get; set; }
			[DispId(0xcf)]
			int Top { get; set; }
			[DispId(0xd0)]
			int Width { get; set; }
			[DispId(0xd1)]
			int Height { get; set; }
			[DispId(210)]
			string LocationName { get; }
			[DispId(0xd3)]
			string LocationURL { get; }
			[DispId(0xd4)]
			bool Busy { get; }
			[DispId(300)]
			void Quit();
			[DispId(0x12d)]
			void ClientToWindow(out int pcx, out int pcy);
			[DispId(0x12e)]
			void PutProperty([In] string property, [In] object vtValue);
			[DispId(0x12f)]
			object GetProperty([In] string property);
			[DispId(0)]
			string Name { get; }
			[DispId(-515)]
			int HWND { get; }
			[DispId(400)]
			string FullName { get; }
			[DispId(0x191)]
			string Path { get; }
			[DispId(0x192)]
			bool Visible { get; set; }
			[DispId(0x193)]
			bool StatusBar { get; set; }
			[DispId(0x194)]
			string StatusText { get; set; }
			[DispId(0x195)]
			int ToolBar { get; set; }
			[DispId(0x196)]
			bool MenuBar { get; set; }
			[DispId(0x197)]
			bool FullScreen { get; set; }
			[DispId(500)]
			void Navigate2([In] ref object URL, [In] ref object flags, [In] ref object targetFrameName, [In] ref object postData, [In] ref object headers);
			[DispId(0x1f5)]
			OLECMDF QueryStatusWB([In] OLECMDID cmdID);
			[DispId(0x1f6)]
			void ExecWB([In] OLECMDID cmdID, [In] OLECMDEXECOPT cmdexecopt, ref object pvaIn, IntPtr pvaOut);
			[DispId(0x1f7)]
			void ShowBrowserBar([In] ref object pvaClsid, [In] ref object pvarShow, [In] ref object pvarSize);
			[DispId(-525)]
			WebBrowserReadyState ReadyState { get; }
			[DispId(550)]
			bool Offline { get; set; }
			[DispId(0x227)]
			bool Silent { get; set; }
			[DispId(0x228)]
			bool RegisterAsBrowser { get; set; }
			[DispId(0x229)]
			bool RegisterAsDropTarget { get; set; }
			[DispId(0x22a)]
			bool TheaterMode { get; set; }
			[DispId(0x22b)]
			bool AddressBar { get; set; }
			[DispId(0x22c)]
			bool Resizable { get; set; }

			#endregion
		}

		#endregion

		#region public interface IWebBrowserApp

		[ComImport]
		//[TypeLibType(4176)]
		[SuppressUnmanagedCodeSecurity]
		[Guid("0002DF05-0000-0000-C000-000000000046")]
		[TypeLibType(TypeLibTypeFlags.FOleAutomation | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden)]
		public interface IWebBrowserApp : IWebBrowser
		{
			#region !

			[DispId(200)]
			object Application { get; }
			[DispId(212)]
			bool Busy { get; }
			[DispId(202)]
			object Container { get; }
			[DispId(203)]
			object Document { get; }
			[DispId(400)]
			string FullName { get; }
			[DispId(407)]
			bool FullScreen { get; set; }
			[DispId(209)]
			int Height { get; set; }
			[DispId(-515)]
			int HWND { get; }
			[DispId(206)]
			int Left { get; set; }
			[DispId(210)]
			string LocationName { get; }
			[DispId(211)]
			string LocationURL { get; }
			[DispId(406)]
			bool MenuBar { get; set; }
			[DispId(0)]
			string Name { get; }
			[DispId(201)]
			object Parent { get; }
			[DispId(401)]
			string Path { get; }
			[DispId(403)]
			bool StatusBar { get; set; }
			[DispId(404)]
			string StatusText { get; set; }
			[DispId(405)]
			int ToolBar { get; set; }
			[DispId(207)]
			int Top { get; set; }
			[DispId(204)]
			bool TopLevelContainer { get; }
			[DispId(205)]
			string Type { get; }
			[DispId(402)]
			bool Visible { get; set; }
			[DispId(208)]
			int Width { get; set; }

			[DispId(301)]
			void ClientToWindow(ref int pcx, ref int pcy);
			[DispId(303)]
			object GetProperty(string Property);
			[DispId(100)]
			void GoBack();
			[DispId(101)]
			void GoForward();
			[DispId(102)]
			void GoHome();
			[DispId(103)]
			void GoSearch();
			[DispId(104)]
			void Navigate(string URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers);
			[DispId(302)]
			void PutProperty(string Property, object vtValue);
			[DispId(300)]
			void Quit();
			[DispId(-550)]
			void Refresh();
			[DispId(105)]
			void Refresh2(ref object Level);
			[DispId(106)]
			void Stop();

			#endregion
		}

		#endregion

		#region interface IWebBrowser

		[ComImport]
		//[TypeLibType(4176)]
		[SuppressUnmanagedCodeSecurity]
		[Guid("EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B")]
		[TypeLibType(TypeLibTypeFlags.FOleAutomation | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FHidden)]
		public interface IWebBrowser
		{
			#region !

			[DispId(200)]
			object Application { get; }
			[DispId(212)]
			bool Busy { get; }
			[DispId(202)]
			object Container { get; }
			[DispId(203)]
			object Document { get; }
			[DispId(209)]
			int Height { get; set; }
			[DispId(206)]
			int Left { get; set; }
			[DispId(210)]
			string LocationName { get; }
			[DispId(211)]
			string LocationURL { get; }
			[DispId(201)]
			object Parent { get; }
			[DispId(207)]
			int Top { get; set; }
			[DispId(204)]
			bool TopLevelContainer { get; }
			[DispId(205)]
			string Type { get; }
			[DispId(208)]
			int Width { get; set; }

			[DispId(100)]
			void GoBack();
			[DispId(101)]
			void GoForward();
			[DispId(102)]
			void GoHome();
			[DispId(103)]
			void GoSearch();
			[DispId(104)]
			void Navigate(string URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers);
			[DispId(-550)]
			void Refresh();
			[DispId(105)]
			void Refresh2(ref object Level);
			[DispId(106)]
			void Stop();

			#endregion
		}

		#endregion

		#region interface WebBrowser

		[ComImport, CoClass(typeof(WebBrowserClass)), Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E")]
		public interface WebBrowser : IWebBrowser2//, DWebBrowserEvents2_Event
		{
		}

		#endregion

		#region class WebBrowserClass

		[ComImport]
		[Guid("8856F961-340A-11D0-A96B-00C04FD705A2")]
		[TypeLibType((short)0x22)]
		[ClassInterface(ClassInterfaceType.None)]
		[DefaultMember("Name")]
		// [ComSourceInterfaces("SHDocVw.DWebBrowserEvents2\0SHDocVw.DWebBrowserEvents\0")]
		class WebBrowserClass// : IWebBrowser2, WebBrowser/*, DWebBrowserEvents2_Event*/, IWebBrowser/*, DWebBrowserEvents_Event*/
		{
		}

		#endregion

		#region struct __MIDL_IWinTypes_0009

		[StructLayout(LayoutKind.Explicit, Pack = 4)]
		struct __MIDL_IWinTypes_0009
		{
			// Fields    
			[FieldOffset(0)]
			public int hInproc;
			[FieldOffset(0)]
			public int hRemote;
		}

		#endregion

		#region struct _RemotableHandle

		[StructLayout(LayoutKind.Sequential, Pack = 4)]
		struct _RemotableHandle
		{
			public int fContext;
			public __MIDL_IWinTypes_0009 u;
		}

		#endregion

		#region struct tagPOINT

		[StructLayout(LayoutKind.Sequential, Pack = 4)]
		struct tagPOINT
		{
			public int x;
			public int y;
		}

		#endregion

		#region interface IDocHostUIHandler/IDocHostUIHandler2/IDocHostShowUI

		[ComImport, Guid("C4D244B0-D43E-11CF-893B-00AA00BDCE1A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		interface IDocHostShowUI
		{
			[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
			void ShowMessage([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrText, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrCaption, [In] uint dwType, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrHelpFile, [In] uint dwHelpContext, [ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.LONG_PTR")] out int plResult);
			[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
			void ShowHelp([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string pszHelpFile, [In] uint uCommand, [In] uint dwData, [In] tagPOINT ptMouse, [Out, MarshalAs(UnmanagedType.IDispatch)] object pDispatchObjectHit);
		}

		#endregion

		#region enum INTERNETFEATURELIST

		enum INTERNETFEATURELIST
		{
			FEATURE_OBJECT_CACHING = 0,
			FEATURE_ZONE_ELEVATION = 1,
			FEATURE_MIME_HANDLING = 2,
			FEATURE_MIME_SNIFFING = 3,
			FEATURE_WINDOW_RESTRICTIONS = 4,
			FEATURE_WEBOC_POPUPMANAGEMENT = 5,
			FEATURE_BEHAVIORS = 6,
			FEATURE_DISABLE_MK_PROTOCOL = 7,
			FEATURE_LOCALMACHINE_LOCKDOWN = 8,
			FEATURE_SECURITYBAND = 9,
			FEATURE_RESTRICT_ACTIVEXINSTALL = 10,
			FEATURE_VALIDATE_NAVIGATE_URL = 11,
			FEATURE_RESTRICT_FILEDOWNLOAD = 12,
			FEATURE_ADDON_MANAGEMENT = 13,
			FEATURE_PROTOCOL_LOCKDOWN = 14,
			FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15,
			FEATURE_SAFE_BINDTOOBJECT = 16,
			FEATURE_UNC_SAVEDFILECHECK = 17,
			FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18,
			FEATURE_TABBED_BROWSING = 19,
			FEATURE_SSLUX = 20,
			FEATURE_DISABLE_NAVIGATION_SOUNDS = 21,
			FEATURE_DISABLE_LEGACY_COMPRESSION = 22,
			FEATURE_FORCE_ADDR_AND_STATUS = 23,
			FEATURE_XMLHTTP = 24,
			FEATURE_DISABLE_TELNET_PROTOCOL = 25,
			FEATURE_FEEDS = 26,
			FEATURE_BLOCK_INPUT_PROMPTS = 27,
			FEATURE_ENTRY_COUNT = 28
		}

		#endregion

		#region InternetExplorerSite

		class InternetExplorerSite : System.Windows.Forms.WebBrowser.WebBrowserSite, IDocHostShowUI
		{
			public InternetExplorerSite(System.Windows.Forms.WebBrowser host) : base(host) { }

			void IDocHostShowUI.ShowMessage(ref _RemotableHandle hwnd, string lpstrText, string lpstrCaption, uint dwType, string lpstrHelpFile, uint dwHelpContext, out int plResult)
			{
				plResult = 0;
				//TODO:自定义    
			}

			void IDocHostShowUI.ShowHelp(ref _RemotableHandle hwnd, string pszHelpFile, uint uCommand, uint dwData, tagPOINT ptMouse, object pDispatchObjectHit)
			{
				//TODO:自定义    
			}

			//protected override WebBrowserSiteBase CreateWebBrowserSiteBase()//WebBrowser
			//{
			//    return base.CreateWebBrowserSiteBase();
			//    return new InternetExplorerSite(this);
			//}
		}

		#endregion

		#endregion

		#region mshtml

		/// <summary>
		/// IHTMLStyle
		/// </summary>
		[Guid("3050F25E-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLStyle
		{
			[DispId(-2147413080)]
			string background { get; set; }
			[DispId(-2147413067)]
			string backgroundAttachment { get; set; }
			[DispId(-501)]
			object backgroundColor { get; set; }
			[DispId(-2147413111)]
			string backgroundImage { get; set; }
			[DispId(-2147413066)]
			string backgroundPosition { get; set; }
			[DispId(-2147413079)]
			object backgroundPositionX { get; set; }
			[DispId(-2147413078)]
			object backgroundPositionY { get; set; }
			[DispId(-2147413068)]
			string backgroundRepeat { get; set; }
			[DispId(-2147413063)]
			string border { get; set; }
			[DispId(-2147413060)]
			string borderBottom { get; set; }
			[DispId(-2147413055)]
			object borderBottomColor { get; set; }
			[DispId(-2147413045)]
			string borderBottomStyle { get; set; }
			[DispId(-2147413050)]
			object borderBottomWidth { get; set; }
			[DispId(-2147413058)]
			string borderColor { get; set; }
			[DispId(-2147413059)]
			string borderLeft { get; set; }
			[DispId(-2147413054)]
			object borderLeftColor { get; set; }
			[DispId(-2147413044)]
			string borderLeftStyle { get; set; }
			[DispId(-2147413049)]
			object borderLeftWidth { get; set; }
			[DispId(-2147413061)]
			string borderRight { get; set; }
			[DispId(-2147413056)]
			object borderRightColor { get; set; }
			[DispId(-2147413046)]
			string borderRightStyle { get; set; }
			[DispId(-2147413051)]
			object borderRightWidth { get; set; }
			[DispId(-2147413048)]
			string borderStyle { get; set; }
			[DispId(-2147413062)]
			string borderTop { get; set; }
			[DispId(-2147413057)]
			object borderTopColor { get; set; }
			[DispId(-2147413047)]
			string borderTopStyle { get; set; }
			[DispId(-2147413052)]
			object borderTopWidth { get; set; }
			[DispId(-2147413053)]
			string borderWidth { get; set; }
			[DispId(-2147413096)]
			string clear { get; set; }
			[DispId(-2147413020)]
			string clip { get; set; }
			[DispId(-2147413110)]
			object color { get; set; }
			[DispId(-2147413013)]
			string cssText { get; set; }
			[DispId(-2147413010)]
			string cursor { get; set; }
			[DispId(-2147413041)]
			string display { get; set; }
			[DispId(-2147413030)]
			string filter { get; set; }
			[DispId(-2147413071)]
			string font { get; set; }
			[DispId(-2147413094)]
			string fontFamily { get; set; }
			[DispId(-2147413093)]
			object fontSize { get; set; }
			[DispId(-2147413088)]
			string fontStyle { get; set; }
			[DispId(-2147413087)]
			string fontVariant { get; set; }
			[DispId(-2147413085)]
			string fontWeight { get; set; }
			[DispId(-2147418106)]
			object height { get; set; }
			[DispId(-2147418109)]
			object left { get; set; }
			[DispId(-2147413104)]
			object letterSpacing { get; set; }
			[DispId(-2147413106)]
			object lineHeight { get; set; }
			[DispId(-2147413037)]
			string listStyle { get; set; }
			[DispId(-2147413038)]
			string listStyleImage { get; set; }
			[DispId(-2147413039)]
			string listStylePosition { get; set; }
			[DispId(-2147413040)]
			string listStyleType { get; set; }
			[DispId(-2147413076)]
			string margin { get; set; }
			[DispId(-2147413073)]
			object marginBottom { get; set; }
			[DispId(-2147413072)]
			object marginLeft { get; set; }
			[DispId(-2147413074)]
			object marginRight { get; set; }
			[DispId(-2147413075)]
			object marginTop { get; set; }
			[DispId(-2147413102)]
			string overflow { get; set; }
			[DispId(-2147413101)]
			string padding { get; set; }
			[DispId(-2147413098)]
			object paddingBottom { get; set; }
			[DispId(-2147413097)]
			object paddingLeft { get; set; }
			[DispId(-2147413099)]
			object paddingRight { get; set; }
			[DispId(-2147413100)]
			object paddingTop { get; set; }
			[DispId(-2147413034)]
			string pageBreakAfter { get; set; }
			[DispId(-2147413035)]
			string pageBreakBefore { get; set; }
			[DispId(-2147414109)]
			int pixelHeight { get; set; }
			[DispId(-2147414111)]
			int pixelLeft { get; set; }
			[DispId(-2147414112)]
			int pixelTop { get; set; }
			[DispId(-2147414110)]
			int pixelWidth { get; set; }
			[DispId(-2147414105)]
			float posHeight { get; set; }
			[DispId(-2147413022)]
			string position { get; }
			[DispId(-2147414107)]
			float posLeft { get; set; }
			[DispId(-2147414108)]
			float posTop { get; set; }
			[DispId(-2147414106)]
			float posWidth { get; set; }
			[DispId(-2147413042)]
			string styleFloat { get; set; }
			[DispId(-2147418040)]
			string textAlign { get; set; }
			[DispId(-2147413077)]
			string textDecoration { get; set; }
			[DispId(-2147413090)]
			bool textDecorationBlink { get; set; }
			[DispId(-2147413092)]
			bool textDecorationLineThrough { get; set; }
			[DispId(-2147413089)]
			bool textDecorationNone { get; set; }
			[DispId(-2147413043)]
			bool textDecorationOverline { get; set; }
			[DispId(-2147413091)]
			bool textDecorationUnderline { get; set; }
			[DispId(-2147413105)]
			object textIndent { get; set; }
			[DispId(-2147413108)]
			string textTransform { get; set; }
			[DispId(-2147418108)]
			object top { get; set; }
			[DispId(-2147413064)]
			object verticalAlign { get; set; }
			[DispId(-2147413032)]
			string visibility { get; set; }
			[DispId(-2147413036)]
			string whiteSpace { get; set; }
			[DispId(-2147418107)]
			object width { get; set; }
			[DispId(-2147413065)]
			object wordSpacing { get; set; }
			[DispId(-2147413021)]
			object zIndex { get; set; }

			[DispId(-2147417610)]
			object getAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417609)]
			bool removeAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417611)]
			void setAttribute(string strAttributeName, object AttributeValue, int lFlags);
			[DispId(-2147414104)]
			string toString();
		}

		/// <summary>
		/// IHTMLFiltersCollection
		/// </summary>
		[Guid("3050F3EE-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLFiltersCollection : IEnumerable
		{
			[DispId(1001)]
			int length { get; }

			[DispId(-4)]
			[TypeLibFunc(65)]
			IEnumerator GetEnumerator();
			[DispId(0)]
			object item(ref object pvarIndex);
		}

		/// <summary>
		/// IHTMLScreen
		/// </summary>
		[TypeLibType(4160)]
		[Guid("3050F35C-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface IHTMLScreen
		{
			[DispId(1006)]
			int availHeight { get; }
			[DispId(1007)]
			int availWidth { get; }
			[DispId(1002)]
			int bufferDepth { get; set; }
			[DispId(1001)]
			int colorDepth { get; }
			[DispId(1008)]
			bool fontSmoothingEnabled { get; }
			[DispId(1004)]
			int height { get; }
			[DispId(1005)]
			int updateInterval { get; set; }
			[DispId(1003)]
			int width { get; }
		}

		/// <summary>
		/// IHTMLFormElement
		/// </summary>
		[TypeLibType(4160)]
		[Guid("3050F1F7-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface IHTMLFormElement : IEnumerable
		{
			[DispId(1001)]
			string action { get; set; }
			[DispId(-2147412995)]
			string dir { get; set; }
			[DispId(1005)]
			object elements { get; }
			[DispId(1003)]
			string encoding { get; set; }
			[DispId(1500)]
			int length { get; set; }
			[DispId(1004)]
			string method { get; set; }
			[DispId(-2147418112)]
			string name { get; set; }
			[DispId(-2147412100)]
			object onreset { get; set; }
			[DispId(-2147412101)]
			object onsubmit { get; set; }
			[DispId(1006)]
			string target { get; set; }

			[DispId(-4)]
			[TypeLibFunc(65)]
			IEnumerator GetEnumerator();
			[DispId(0)]
			object item(object name, object index);
			[DispId(1010)]
			void reset();
			[DispId(1009)]
			void submit();
			[DispId(1502)]
			object tags(object tagName);
		}

		/// <summary>
		/// IHTMLOptionElement
		/// </summary>
		[Guid("3050F211-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLOptionElement
		{
			[DispId(1003)]
			bool defaultSelected { get; set; }
			[DispId(1006)]
			IHTMLFormElement form { get; }
			[DispId(1005)]
			int index { get; set; }
			[DispId(1001)]
			bool selected { get; set; }
			[DispId(1004)]
			string text { get; set; }
			[DispId(1002)]
			string value { get; set; }
		}

		/// <summary>
		/// IHTMLOptionElementFactory
		/// </summary>
		[Guid("3050F38C-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLOptionElementFactory
		{
			[DispId(0)]
			IHTMLOptionElement create(object text, object value, object defaultSelected, object selected);
		}

		/// <summary>
		/// HTMLOptionElementFactory
		/// </summary>
		[CoClass(typeof(HTMLOptionElementFactoryClass))]
		[Guid("3050F38C-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface HTMLOptionElementFactory : IHTMLOptionElementFactory
		{
		}

		/// <summary>
		/// IHTMLImgElement
		/// </summary>
		[Guid("3050F240-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLImgElement
		{
			[DispId(-2147418039)]
			string align { get; set; }
			[DispId(1002)]
			string alt { get; set; }
			[DispId(1004)]
			object border { get; set; }
			[DispId(1010)]
			bool complete { get; }
			[DispId(1009)]
			string dynsrc { get; set; }
			[DispId(2012)]
			string fileCreatedDate { get; }
			[DispId(2013)]
			string fileModifiedDate { get; }
			[DispId(2011)]
			string fileSize { get; }
			[DispId(2014)]
			string fileUpdatedDate { get; }
			[DispId(-2147418106)]
			int height { get; set; }
			[DispId(2016)]
			string href { get; }
			[DispId(1006)]
			int hspace { get; set; }
			[DispId(2002)]
			bool isMap { get; set; }
			[DispId(1011)]
			object loop { get; set; }
			[DispId(1007)]
			string lowsrc { get; set; }
			[DispId(2010)]
			string mimeType { get; }
			[DispId(-2147418112)]
			string name { get; set; }
			[DispId(2017)]
			string nameProp { get; }
			[DispId(-2147412084)]
			object onabort { get; set; }
			[DispId(-2147412083)]
			object onerror { get; set; }
			[DispId(-2147412080)]
			object onload { get; set; }
			[DispId(2015)]
			string protocol { get; }
			[DispId(-2147412996)]
			string readyState { get; }
			[DispId(1003)]
			string src { get; set; }
			[DispId(1013)]
			string Start { get; set; }
			[DispId(2008)]
			string useMap { get; set; }
			[DispId(1008)]
			string vrml { get; set; }
			[DispId(1005)]
			int vspace { get; set; }
			[DispId(-2147418107)]
			int width { get; set; }
		}

		/// <summary>
		/// IHTMLImageElementFactory
		/// </summary>
		[Guid("3050F38E-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLImageElementFactory
		{
			[DispId(0)]
			IHTMLImgElement create(object width, object height);
		}

		/// <summary>
		/// HTMLImageElementFactory
		/// </summary>
		[CoClass(typeof(HTMLImageElementFactoryClass))]
		[Guid("3050F38E-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface HTMLImageElementFactory : IHTMLImageElementFactory
		{
		}

		/// <summary>
		/// IOmHistory
		/// </summary>
		[TypeLibType(4160)]
		[Guid("FECEAAA2-8405-11CF-8BA1-00AA00476DA6")]
		public interface IOmHistory
		{
			[DispId(1)]
			short length { get; }

			[DispId(2)]
			void back(ref object pvargdistance);
			[DispId(3)]
			void forward(ref object pvargdistance);
			[DispId(4)]
			void go(ref object pvargdistance);
		}

		/// <summary>
		/// HTMLHistory
		/// </summary>
		[Guid("FECEAAA2-8405-11CF-8BA1-00AA00476DA6")]
		[CoClass(typeof(HTMLHistoryClass))]
		public interface HTMLHistory : IOmHistory
		{
		}

		/// <summary>
		/// IHTMLEventObj
		/// </summary>
		[Guid("3050F32D-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLEventObj
		{
			[DispId(1002)]
			bool altKey { get; }
			[DispId(1012)]
			int button { get; }
			[DispId(1008)]
			bool cancelBubble { get; set; }
			[DispId(1020)]
			int clientX { get; }
			[DispId(1021)]
			int clientY { get; }
			[DispId(1003)]
			bool ctrlKey { get; }
			[DispId(1009)]
			IHTMLElement fromElement { get; }
			[DispId(1011)]
			int keyCode { get; set; }
			[DispId(1022)]
			int offsetX { get; }
			[DispId(1023)]
			int offsetY { get; }
			[DispId(1014)]
			string qualifier { get; }
			[DispId(1015)]
			int reason { get; }
			[DispId(1007)]
			object returnValue { get; set; }
			[DispId(1024)]
			int screenX { get; }
			[DispId(1025)]
			int screenY { get; }
			[DispId(1004)]
			bool shiftKey { get; }
			[DispId(1001)]
			IHTMLElement srcElement { get; }
			[DispId(1026)]
			object srcFilter { get; }
			[DispId(1010)]
			IHTMLElement toElement { get; }
			[DispId(1013)]
			string type { get; }
			[DispId(1005)]
			int x { get; }
			[DispId(1006)]
			int y { get; }
		}

		/// <summary>
		/// IHTMLMimeTypesCollection
		/// </summary>
		[Guid("3050F3FC-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLMimeTypesCollection
		{
			[DispId(1)]
			int length { get; }
		}

		/// <summary>
		/// CMimeTypes
		/// </summary>
		[Guid("3050F3FC-98B5-11CF-BB82-00AA00BDCE0B")]
		[CoClass(typeof(CMimeTypesClass))]
		public interface CMimeTypes : IHTMLMimeTypesCollection
		{
		}

		/// <summary>
		/// IHTMLOpsProfile
		/// </summary>
		[Guid("3050F401-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLOpsProfile
		{
			[DispId(7)]
			bool addReadRequest(string name, object reserved);
			[DispId(1)]
			bool addRequest(string name, object reserved);
			[DispId(2)]
			void clearRequest();
			[DispId(6)]
			bool commitChanges();
			[DispId(8)]
			void doReadRequest(object usage, object fname, object domain, object path, object expire, object reserved);
			[DispId(3)]
			void doRequest(object usage, object fname, object domain, object path, object expire, object reserved);
			[DispId(9)]
			bool doWriteRequest();
			[DispId(4)]
			string getAttribute(string name);
			[DispId(5)]
			bool setAttribute(string name, string value, object prefs);
		}

		/// <summary>
		/// COpsProfile
		/// </summary>
		[CoClass(typeof(COpsProfileClass))]
		[Guid("3050F401-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface COpsProfile : IHTMLOpsProfile
		{
		}

		/// <summary>
		/// IHTMLPluginsCollection
		/// </summary>
		[Guid("3050F3FD-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLPluginsCollection
		{
			[DispId(1)]
			int length { get; }

			[DispId(2)]
			void refresh(bool reload);
		}

		/// <summary>
		/// CPlugins
		/// </summary>
		[Guid("3050F3FD-98B5-11CF-BB82-00AA00BDCE0B")]
		[CoClass(typeof(CPluginsClass))]
		public interface CPlugins : IHTMLPluginsCollection
		{
		}

		/// <summary>
		/// IOmNavigator
		/// </summary>
		[Guid("FECEAAA5-8405-11CF-8BA1-00AA00476DA6")]
		[TypeLibType(4160)]
		public interface IOmNavigator
		{
			[DispId(1)]
			string appCodeName { get; }
			[DispId(17)]
			string appMinorVersion { get; }
			[DispId(2)]
			string appName { get; }
			[DispId(3)]
			string appVersion { get; }
			[DispId(14)]
			string browserLanguage { get; }
			[DispId(18)]
			int connectionSpeed { get; }
			[DispId(9)]
			bool cookieEnabled { get; }
			[DispId(12)]
			string cpuClass { get; }
			[DispId(7)]
			CMimeTypes mimeTypes { get; }
			[DispId(19)]
			bool onLine { get; }
			[DispId(10)]
			COpsProfile opsProfile { get; }
			[DispId(16)]
			string platform { get; }
			[DispId(8)]
			CPlugins plugins { get; }
			[DispId(13)]
			string systemLanguage { get; }
			[DispId(4)]
			string userAgent { get; }
			[DispId(15)]
			string userLanguage { get; }
			[DispId(20)]
			COpsProfile userProfile { get; }

			[DispId(5)]
			bool javaEnabled();
			[DispId(6)]
			bool taintEnabled();
			[DispId(11)]
			string toString();
		}

		/// <summary>
		/// HTMLNavigator
		/// </summary>
		[CoClass(typeof(HTMLNavigatorClass))]
		[Guid("FECEAAA5-8405-11CF-8BA1-00AA00476DA6")]
		public interface HTMLNavigator : IOmNavigator
		{
		}

		/// <summary>
		/// IHTMLRuleStyle
		/// </summary>
		[Guid("3050F3CF-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLRuleStyle
		{
			[DispId(-2147413080)]
			string background { get; set; }
			[DispId(-2147413067)]
			string backgroundAttachment { get; set; }
			[DispId(-501)]
			object backgroundColor { get; set; }
			[DispId(-2147413111)]
			string backgroundImage { get; set; }
			[DispId(-2147413066)]
			string backgroundPosition { get; set; }
			[DispId(-2147413079)]
			object backgroundPositionX { get; set; }
			[DispId(-2147413078)]
			object backgroundPositionY { get; set; }
			[DispId(-2147413068)]
			string backgroundRepeat { get; set; }
			[DispId(-2147413063)]
			string border { get; set; }
			[DispId(-2147413060)]
			string borderBottom { get; set; }
			[DispId(-2147413055)]
			object borderBottomColor { get; set; }
			[DispId(-2147413045)]
			string borderBottomStyle { get; set; }
			[DispId(-2147413050)]
			object borderBottomWidth { get; set; }
			[DispId(-2147413058)]
			string borderColor { get; set; }
			[DispId(-2147413059)]
			string borderLeft { get; set; }
			[DispId(-2147413054)]
			object borderLeftColor { get; set; }
			[DispId(-2147413044)]
			string borderLeftStyle { get; set; }
			[DispId(-2147413049)]
			object borderLeftWidth { get; set; }
			[DispId(-2147413061)]
			string borderRight { get; set; }
			[DispId(-2147413056)]
			object borderRightColor { get; set; }
			[DispId(-2147413046)]
			string borderRightStyle { get; set; }
			[DispId(-2147413051)]
			object borderRightWidth { get; set; }
			[DispId(-2147413048)]
			string borderStyle { get; set; }
			[DispId(-2147413062)]
			string borderTop { get; set; }
			[DispId(-2147413057)]
			object borderTopColor { get; set; }
			[DispId(-2147413047)]
			string borderTopStyle { get; set; }
			[DispId(-2147413052)]
			object borderTopWidth { get; set; }
			[DispId(-2147413053)]
			string borderWidth { get; set; }
			[DispId(-2147413096)]
			string clear { get; set; }
			[DispId(-2147413020)]
			string clip { get; set; }
			[DispId(-2147413110)]
			object color { get; set; }
			[DispId(-2147413013)]
			string cssText { get; set; }
			[DispId(-2147413010)]
			string cursor { get; set; }
			[DispId(-2147413041)]
			string display { get; set; }
			[DispId(-2147413030)]
			string filter { get; set; }
			[DispId(-2147413071)]
			string font { get; set; }
			[DispId(-2147413094)]
			string fontFamily { get; set; }
			[DispId(-2147413093)]
			object fontSize { get; set; }
			[DispId(-2147413088)]
			string fontStyle { get; set; }
			[DispId(-2147413087)]
			string fontVariant { get; set; }
			[DispId(-2147413085)]
			string fontWeight { get; set; }
			[DispId(-2147418106)]
			object height { get; set; }
			[DispId(-2147418109)]
			object left { get; set; }
			[DispId(-2147413104)]
			object letterSpacing { get; set; }
			[DispId(-2147413106)]
			object lineHeight { get; set; }
			[DispId(-2147413037)]
			string listStyle { get; set; }
			[DispId(-2147413038)]
			string listStyleImage { get; set; }
			[DispId(-2147413039)]
			string listStylePosition { get; set; }
			[DispId(-2147413040)]
			string listStyleType { get; set; }
			[DispId(-2147413076)]
			string margin { get; set; }
			[DispId(-2147413073)]
			object marginBottom { get; set; }
			[DispId(-2147413072)]
			object marginLeft { get; set; }
			[DispId(-2147413074)]
			object marginRight { get; set; }
			[DispId(-2147413075)]
			object marginTop { get; set; }
			[DispId(-2147413102)]
			string overflow { get; set; }
			[DispId(-2147413101)]
			string padding { get; set; }
			[DispId(-2147413098)]
			object paddingBottom { get; set; }
			[DispId(-2147413097)]
			object paddingLeft { get; set; }
			[DispId(-2147413099)]
			object paddingRight { get; set; }
			[DispId(-2147413100)]
			object paddingTop { get; set; }
			[DispId(-2147413034)]
			string pageBreakAfter { get; set; }
			[DispId(-2147413035)]
			string pageBreakBefore { get; set; }
			[DispId(-2147413022)]
			string position { get; }
			[DispId(-2147413042)]
			string styleFloat { get; set; }
			[DispId(-2147418040)]
			string textAlign { get; set; }
			[DispId(-2147413077)]
			string textDecoration { get; set; }
			[DispId(-2147413090)]
			bool textDecorationBlink { get; set; }
			[DispId(-2147413092)]
			bool textDecorationLineThrough { get; set; }
			[DispId(-2147413089)]
			bool textDecorationNone { get; set; }
			[DispId(-2147413043)]
			bool textDecorationOverline { get; set; }
			[DispId(-2147413091)]
			bool textDecorationUnderline { get; set; }
			[DispId(-2147413105)]
			object textIndent { get; set; }
			[DispId(-2147413108)]
			string textTransform { get; set; }
			[DispId(-2147418108)]
			object top { get; set; }
			[DispId(-2147413064)]
			object verticalAlign { get; set; }
			[DispId(-2147413032)]
			string visibility { get; set; }
			[DispId(-2147413036)]
			string whiteSpace { get; set; }
			[DispId(-2147418107)]
			object width { get; set; }
			[DispId(-2147413065)]
			object wordSpacing { get; set; }
			[DispId(-2147413021)]
			object zIndex { get; set; }

			[DispId(-2147417610)]
			object getAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417609)]
			bool removeAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417611)]
			void setAttribute(string strAttributeName, object AttributeValue, int lFlags);
		}

		/// <summary>
		/// IHTMLStyleSheetRule
		/// </summary>
		[Guid("3050F357-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLStyleSheetRule
		{
			[DispId(1002)]
			bool readOnly { get; }
			[DispId(1001)]
			string selectorText { get; set; }
			[DispId(-2147418038)]
			IHTMLRuleStyle style { get; }
		}

		/// <summary>
		/// HTMLStyleSheetRule
		/// </summary>
		[Guid("3050F357-98B5-11CF-BB82-00AA00BDCE0B")]
		[CoClass(typeof(HTMLStyleSheetRuleClass))]
		public interface HTMLStyleSheetRule : IHTMLStyleSheetRule
		{
		}

		/// <summary>
		/// IHTMLStyleSheetRulesCollection
		/// </summary>
		[Guid("3050F2E5-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLStyleSheetRulesCollection
		{
			[DispId(1001)]
			int length { get; }

			[DispId(0)]
			HTMLStyleSheetRule item(int index);
		}

		/// <summary>
		/// HTMLStyleSheetRulesCollection
		/// </summary>
		[CoClass(typeof(HTMLStyleSheetRulesCollectionClass))]
		[Guid("3050F2E5-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface HTMLStyleSheetRulesCollection : IHTMLStyleSheetRulesCollection
		{
		}

		/// <summary>
		/// IHTMLStyleSheet
		/// </summary>
		[Guid("3050F2E3-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLStyleSheet
		{
			[DispId(1014)]
			string cssText { get; set; }
			[DispId(-2147418036)]
			bool disabled { get; set; }
			[DispId(1006)]
			string href { get; set; }
			[DispId(1008)]
			string id { get; }
			[DispId(1005)]
			HTMLStyleSheetsCollection imports { get; }
			[DispId(1013)]
			string media { get; set; }
			[DispId(1003)]
			IHTMLElement owningElement { get; }
			[DispId(1002)]
			IHTMLStyleSheet parentStyleSheet { get; }
			[DispId(1004)]
			bool readOnly { get; }
			[DispId(1015)]
			HTMLStyleSheetRulesCollection rules { get; }
			[DispId(1001)]
			string title { get; set; }
			[DispId(1007)]
			string type { get; }

			[DispId(1009)]
			int addImport(string bstrUrl, int lIndex);
			[DispId(1010)]
			int addRule(string bstrSelector, string bstrStyle, int lIndex);
			[DispId(1011)]
			void removeImport(int lIndex);
			[DispId(1012)]
			void removeRule(int lIndex);
		}

		/// <summary>
		/// IHTMLStyleSheetsCollection
		/// </summary>
		[Guid("3050F37E-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLStyleSheetsCollection : IEnumerable
		{
			[DispId(1001)]
			int length { get; }

			[TypeLibFunc(65)]
			[DispId(-4)]
			IEnumerator GetEnumerator();
			[DispId(0)]
			object item(ref object pvarIndex);
		}

		/// <summary>
		/// HTMLStyleSheetsCollection
		/// </summary>
		[Guid("3050F37E-98B5-11CF-BB82-00AA00BDCE0B")]
		[CoClass(typeof(HTMLStyleSheetsCollectionClass))]
		public interface HTMLStyleSheetsCollection : IHTMLStyleSheetsCollection
		{
		}

		/// <summary>
		/// IHTMLLocation
		/// </summary>
		[TypeLibType(4160)]
		[Guid("163BB1E0-6E00-11CF-837A-48DC04C10000")]
		public interface IHTMLLocation
		{
			[DispId(7)]
			string hash { get; set; }
			[DispId(2)]
			string host { get; set; }
			[DispId(3)]
			string hostname { get; set; }
			[DispId(0)]
			string href { get; set; }
			[DispId(5)]
			string pathname { get; set; }
			[DispId(4)]
			string port { get; set; }
			[DispId(1)]
			string protocol { get; set; }
			[DispId(6)]
			string search { get; set; }

			[DispId(10)]
			void assign(string bstr);
			[DispId(8)]
			void reload(bool flag);
			[DispId(9)]
			void replace(string bstr);
			[DispId(11)]
			string toString();
		}

		/// <summary>
		/// HTMLLocation
		/// </summary>
		[Guid("163BB1E0-6E00-11CF-837A-48DC04C10000")]
		[CoClass(typeof(HTMLLocationClass))]
		public interface HTMLLocation : IHTMLLocation
		{
		}

		/// <summary>
		/// IHTMLSelectionObject
		/// </summary>
		[Guid("3050F25A-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLSelectionObject
		{
			[DispId(1004)]
			string type { get; }

			[DispId(1003)]
			void clear();
			[DispId(1001)]
			object createRange();
			[DispId(1002)]
			void empty();
		}

		/// <summary>
		/// IHTMLFramesCollection2
		/// </summary>
		[Guid("332C4426-26CB-11D0-B483-00C04FD90119")]
		[TypeLibType(4160)]
		public interface IHTMLFramesCollection2
		{
			[DispId(1001)]
			int length { get; }

			[DispId(0)]
			object item(ref object pvarIndex);
		}

		/// <summary>
		/// FramesCollection
		/// </summary>
		[CoClass(typeof(FramesCollectionClass))]
		[Guid("332C4426-26CB-11D0-B483-00C04FD90119")]
		public interface FramesCollection : IHTMLFramesCollection2
		{
		}

		/// <summary>
		/// IHTMLDocument
		/// </summary>
		[Guid("626FC520-A41E-11CF-A731-00A0C9082637")]
		[TypeLibType(4160)]
		public interface IHTMLDocument
		{
			[DispId(1001)]
			object Script { get; }
		}

		/// <summary>
		/// IHTMLDocument2
		/// </summary>
		[TypeLibType(4160)]
		[Guid("332C4425-26CB-11D0-B483-00C04FD90119")]
		public interface IHTMLDocument2 : IHTMLDocument
		{
			[DispId(1005)]
			IHTMLElement activeElement { get; }
			[DispId(1022)]
			object alinkColor { get; set; }
			[DispId(1003)]
			IHTMLElementCollection all { get; }
			[DispId(1007)]
			IHTMLElementCollection anchors { get; }
			[DispId(1008)]
			IHTMLElementCollection applets { get; }
			[DispId(-501)]
			object bgColor { get; set; }
			[DispId(1004)]
			IHTMLElement body { get; }
			[DispId(1032)]
			string charset { get; set; }
			[DispId(1030)]
			string cookie { get; set; }
			[DispId(1033)]
			string defaultCharset { get; set; }
			[DispId(1014)]
			string designMode { get; set; }
			[DispId(1029)]
			string domain { get; set; }
			[DispId(1015)]
			IHTMLElementCollection embeds { get; }
			[DispId(1031)]
			bool expando { get; set; }
			[DispId(-2147413110)]
			object fgColor { get; set; }
			[DispId(1043)]
			string fileCreatedDate { get; }
			[DispId(1044)]
			string fileModifiedDate { get; }
			[DispId(1042)]
			string fileSize { get; }
			[DispId(1045)]
			string fileUpdatedDate { get; }
			[DispId(1010)]
			IHTMLElementCollection forms { get; }
			[DispId(1019)]
			FramesCollection frames { get; }
			[DispId(1011)]
			IHTMLElementCollection images { get; }
			[DispId(1028)]
			string lastModified { get; }
			[DispId(1024)]
			object linkColor { get; set; }
			[DispId(1009)]
			IHTMLElementCollection links { get; }
			[DispId(1026)]
			HTMLLocation location { get; }
			[DispId(1041)]
			string mimeType { get; }
			[DispId(1048)]
			string nameProp { get; }
			[DispId(-2147412090)]
			object onafterupdate { get; set; }
			[DispId(-2147412091)]
			object onbeforeupdate { get; set; }
			[DispId(-2147412104)]
			object onclick { get; set; }
			[DispId(-2147412103)]
			object ondblclick { get; set; }
			[DispId(-2147412077)]
			object ondragstart { get; set; }
			[DispId(-2147412074)]
			object onerrorupdate { get; set; }
			[DispId(-2147412099)]
			object onhelp { get; set; }
			[DispId(-2147412107)]
			object onkeydown { get; set; }
			[DispId(-2147412105)]
			object onkeypress { get; set; }
			[DispId(-2147412106)]
			object onkeyup { get; set; }
			[DispId(-2147412110)]
			object onmousedown { get; set; }
			[DispId(-2147412108)]
			object onmousemove { get; set; }
			[DispId(-2147412111)]
			object onmouseout { get; set; }
			[DispId(-2147412112)]
			object onmouseover { get; set; }
			[DispId(-2147412109)]
			object onmouseup { get; set; }
			[DispId(-2147412087)]
			object onreadystatechange { get; set; }
			[DispId(-2147412093)]
			object onrowenter { get; set; }
			[DispId(-2147412094)]
			object onrowexit { get; set; }
			[DispId(-2147412075)]
			object onselectstart { get; set; }
			[DispId(1034)]
			IHTMLWindow2 parentWindow { get; }
			[DispId(1021)]
			IHTMLElementCollection plugins { get; }
			[DispId(1047)]
			string protocol { get; }
			[DispId(1018)]
			string readyState { get; }
			[DispId(1027)]
			string referrer { get; }
			[DispId(1001)]
			object Script { get; }
			[DispId(1013)]
			IHTMLElementCollection scripts { get; }
			[DispId(1046)]
			string security { get; }
			[DispId(1017)]
			IHTMLSelectionObject selection { get; }
			[DispId(1069)]
			HTMLStyleSheetsCollection styleSheets { get; }
			[DispId(1012)]
			string title { get; set; }
			[DispId(1025)]
			string url { get; set; }
			[DispId(1023)]
			object vlinkColor { get; set; }

			[DispId(1058)]
			void clear();
			[DispId(1057)]
			void close();
			[DispId(1067)]
			IHTMLElement createElement(string eTag);
			[DispId(1071)]
			IHTMLStyleSheet createStyleSheet(string bstrHref, int lIndex);
			[DispId(1068)]
			IHTMLElement elementFromPoint(int x, int y);
			[DispId(1065)]
			bool execCommand(string cmdID, bool showUI, object value);
			[DispId(1066)]
			bool execCommandShowHelp(string cmdID);
			[DispId(1056)]
			object open(string url, object name, object features, object replace);
			[DispId(1060)]
			bool queryCommandEnabled(string cmdID);
			[DispId(1062)]
			bool queryCommandIndeterm(string cmdID);
			[DispId(1061)]
			bool queryCommandState(string cmdID);
			[DispId(1059)]
			bool queryCommandSupported(string cmdID);
			[DispId(1063)]
			string queryCommandText(string cmdID);
			[DispId(1064)]
			object queryCommandValue(string cmdID);
			[DispId(1070)]
			string toString();
			[DispId(1054)]
			void write(params object[] psarray);
			[DispId(1055)]
			void writeln(params object[] psarray);
		}

		/// <summary>
		/// IHTMLDocument3
		/// </summary>
		[Guid("3050F485-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType(4160)]
		public interface IHTMLDocument3
		{
			[DispId(1080)]
			string baseUrl { get; set; }
			[DispId(-2147417063)]
			object childNodes { get; }
			[DispId(-2147412995)]
			string dir { get; set; }
			[DispId(1075)]
			IHTMLElement documentElement { get; }
			[DispId(1079)]
			bool enableDownload { get; set; }
			[DispId(1082)]
			bool inheritStyleSheets { get; set; }
			[DispId(-2147412043)]
			object onbeforeeditfocus { get; set; }
			[DispId(-2147412048)]
			object oncellchange { get; set; }
			[DispId(-2147412047)]
			object oncontextmenu { get; set; }
			[DispId(-2147412071)]
			object ondataavailable { get; set; }
			[DispId(-2147412072)]
			object ondatasetchanged { get; set; }
			[DispId(-2147412070)]
			object ondatasetcomplete { get; set; }
			[DispId(-2147412065)]
			object onpropertychange { get; set; }
			[DispId(-2147412050)]
			object onrowsdelete { get; set; }
			[DispId(-2147412049)]
			object onrowsinserted { get; set; }
			[DispId(-2147412044)]
			object onstop { get; set; }
			[DispId(1078)]
			IHTMLDocument2 parentDocument { get; }
			[DispId(1077)]
			string uniqueID { get; }

			[DispId(-2147417605)]
			bool attachEvent(string @event, object pdisp);
			[DispId(1076)]
			IHTMLDocument2 createDocumentFragment();
			[DispId(1074)]
			IHTMLDOMNode createTextNode(string text);
			[DispId(-2147417604)]
			void detachEvent(string @event, object pdisp);
			[DispId(1088)]
			IHTMLElement getElementById(string v);
			[DispId(1086)]
			IHTMLElementCollection getElementsByName(string v);
			[DispId(1087)]
			IHTMLElementCollection getElementsByTagName(string v);
			[DispId(1073)]
			void recalc(bool fForce);
			[DispId(1072)]
			void releaseCapture();
		}

		/// <summary>
		/// IHTMLWindow2
		/// </summary>
		[Guid("332C4427-26CB-11D0-B483-00C04FD90119")]
		[TypeLibType(4160)]
		public interface IHTMLWindow2 : IHTMLFramesCollection2
		{
			[DispId(1153)]
			object _newEnum { get; }
			[DispId(1161)]
			HTMLNavigator clientInformation { get; }
			[DispId(23)]
			bool closed { get; }
			[DispId(1101)]
			string defaultStatus { get; set; }
			[DispId(1151)]
			IHTMLDocument2 document { get; }
			[DispId(1152)]
			IHTMLEventObj @event { get; }
			[DispId(1169)]
			object external { get; }
			[DispId(1100)]
			FramesCollection frames { get; }
			[DispId(2)]
			HTMLHistory history { get; }
			[DispId(1125)]
			HTMLImageElementFactory Image { get; }
			[DispId(1001)]
			int length { get; }
			[DispId(14)]
			HTMLLocation location { get; }
			[DispId(11)]
			string name { get; set; }
			[DispId(5)]
			HTMLNavigator navigator { get; }
			[DispId(1164)]
			object offscreenBuffering { get; set; }
			[DispId(-2147412073)]
			object onbeforeunload { get; set; }
			[DispId(-2147412097)]
			object onblur { get; set; }
			[DispId(-2147412083)]
			object onerror { get; set; }
			[DispId(-2147412098)]
			object onfocus { get; set; }
			[DispId(-2147412099)]
			object onhelp { get; set; }
			[DispId(-2147412080)]
			object onload { get; set; }
			[DispId(-2147412076)]
			object onresize { get; set; }
			[DispId(-2147412081)]
			object onscroll { get; set; }
			[DispId(-2147412079)]
			object onunload { get; set; }
			[DispId(4)]
			object opener { get; set; }
			[DispId(1157)]
			HTMLOptionElementFactory Option { get; }
			[DispId(12)]
			IHTMLWindow2 parent { get; }
			[DispId(1156)]
			IHTMLScreen screen { get; }
			[DispId(20)]
			IHTMLWindow2 self { get; }
			[DispId(1102)]
			string status { get; set; }
			[DispId(21)]
			IHTMLWindow2 top { get; }
			[DispId(22)]
			IHTMLWindow2 window { get; }

			[DispId(1105)]
			void alert(string message);
			[DispId(1159)]
			void blur();
			[DispId(1163)]
			void clearInterval(int timerID);
			[DispId(1104)]
			void clearTimeout(int timerID);
			[DispId(3)]
			void close();
			[DispId(1110)]
			bool confirm(string message);
			[DispId(1165)]
			object execScript(string code, string language);
			[DispId(1158)]
			void focus();
			[DispId(0)]
			object item(ref object pvarIndex);
			[DispId(7)]
			void moveBy(int x, int y);
			[DispId(6)]
			void moveTo(int x, int y);
			[DispId(25)]
			void navigate(string url);
			[DispId(13)]
			IHTMLWindow2 open(string url, string name, string features, bool replace);
			[DispId(1111)]
			object prompt(string message, string defstr);
			[DispId(8)]
			void resizeBy(int x, int y);
			[DispId(9)]
			void resizeTo(int x, int y);
			[DispId(1160)]
			void scroll(int x, int y);
			[DispId(1167)]
			void scrollBy(int x, int y);
			[DispId(1168)]
			void scrollTo(int x, int y);
			[DispId(1173)]
			int setInterval(string expression, int msec, ref object language);
			[DispId(1172)]
			int setTimeout(string expression, int msec, ref object language);
			[DispId(1155)]
			void showHelp(string helpURL, object helpArg, string features);
			[DispId(1154)]
			object showModalDialog(string dialog, ref object varArgIn, ref object varOptions);
			[DispId(1166)]
			string toString();
		}

		/// <summary>
		/// IHTMLElement
		/// </summary>
		[TypeLibType(4160)]
		[Guid("3050F1FF-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface IHTMLElement
		{
			[DispId(-2147417074)]
			object all { get; }
			[DispId(-2147417075)]
			object children { get; }
			[DispId(-2147417111)]
			string className { get; set; }
			[DispId(-2147417094)]
			object document { get; }
			[DispId(-2147417077)]
			IHTMLFiltersCollection filters { get; }
			[DispId(-2147417110)]
			string id { get; set; }
			[DispId(-2147417086)]
			string innerHTML { get; set; }
			[DispId(-2147417085)]
			string innerText { get; set; }
			[DispId(-2147417078)]
			bool isTextEdit { get; }
			[DispId(-2147413103)]
			string lang { get; set; }
			[DispId(-2147413012)]
			string language { get; set; }
			[DispId(-2147417101)]
			int offsetHeight { get; }
			[DispId(-2147417104)]
			int offsetLeft { get; }
			[DispId(-2147417100)]
			IHTMLElement offsetParent { get; }
			[DispId(-2147417103)]
			int offsetTop { get; }
			[DispId(-2147417102)]
			int offsetWidth { get; }
			[DispId(-2147412090)]
			object onafterupdate { get; set; }
			[DispId(-2147412091)]
			object onbeforeupdate { get; set; }
			[DispId(-2147412104)]
			object onclick { get; set; }
			[DispId(-2147412071)]
			object ondataavailable { get; set; }
			[DispId(-2147412072)]
			object ondatasetchanged { get; set; }
			[DispId(-2147412070)]
			object ondatasetcomplete { get; set; }
			[DispId(-2147412103)]
			object ondblclick { get; set; }
			[DispId(-2147412077)]
			object ondragstart { get; set; }
			[DispId(-2147412074)]
			object onerrorupdate { get; set; }
			[DispId(-2147412069)]
			object onfilterchange { get; set; }
			[DispId(-2147412099)]
			object onhelp { get; set; }
			[DispId(-2147412107)]
			object onkeydown { get; set; }
			[DispId(-2147412105)]
			object onkeypress { get; set; }
			[DispId(-2147412106)]
			object onkeyup { get; set; }
			[DispId(-2147412110)]
			object onmousedown { get; set; }
			[DispId(-2147412108)]
			object onmousemove { get; set; }
			[DispId(-2147412111)]
			object onmouseout { get; set; }
			[DispId(-2147412112)]
			object onmouseover { get; set; }
			[DispId(-2147412109)]
			object onmouseup { get; set; }
			[DispId(-2147412093)]
			object onrowenter { get; set; }
			[DispId(-2147412094)]
			object onrowexit { get; set; }
			[DispId(-2147412075)]
			object onselectstart { get; set; }
			[DispId(-2147417084)]
			string outerHTML { get; set; }
			[DispId(-2147417083)]
			string outerText { get; set; }
			[DispId(-2147418104)]
			IHTMLElement parentElement { get; }
			[DispId(-2147417080)]
			IHTMLElement parentTextEdit { get; }
			[DispId(-2147417087)]
			object recordNumber { get; }
			[DispId(-2147417088)]
			int sourceIndex { get; }
			[DispId(-2147418038)]
			IHTMLStyle style { get; }
			[DispId(-2147417108)]
			string tagName { get; }
			[DispId(-2147418043)]
			string title { get; set; }

			[DispId(-2147417079)]
			void click();
			[DispId(-2147417092)]
			bool contains(IHTMLElement pChild);
			[DispId(-2147417610)]
			object getAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417082)]
			void insertAdjacentHTML(string where, string html);
			[DispId(-2147417081)]
			void insertAdjacentText(string where, string text);
			[DispId(-2147417609)]
			bool removeAttribute(string strAttributeName, int lFlags);
			[DispId(-2147417093)]
			void scrollIntoView(object varargStart);
			[DispId(-2147417611)]
			void setAttribute(string strAttributeName, object AttributeValue, int lFlags);
			[DispId(-2147417076)]
			string toString();
		}

		/// <summary>
		/// IHTMLElementCollection
		/// </summary>
		[TypeLibType(4160)]
		[Guid("3050F21F-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface IHTMLElementCollection : IEnumerable
		{
			[DispId(1500)]
			int length { get; set; }

			[TypeLibFunc(65)]
			[DispId(-4)]
			IEnumerator GetEnumerator();
			[DispId(0)]
			object item(object name, object index);
			[DispId(1502)]
			object tags(object tagName);
			[DispId(1501)]
			string toString();
		}

		/// <summary>
		/// IHTMLDOMNode
		/// </summary>
		[TypeLibType(4160)]
		[Guid("3050F5DA-98B5-11CF-BB82-00AA00BDCE0B")]
		public interface IHTMLDOMNode
		{
			[DispId(-2147417062)]
			object attributes { get; }
			[DispId(-2147417063)]
			object childNodes { get; }
			[DispId(-2147417036)]
			IHTMLDOMNode firstChild { get; }
			[DispId(-2147417035)]
			IHTMLDOMNode lastChild { get; }
			[DispId(-2147417033)]
			IHTMLDOMNode nextSibling { get; }
			[DispId(-2147417038)]
			string nodeName { get; }
			[DispId(-2147417066)]
			int nodeType { get; }
			[DispId(-2147417037)]
			object nodeValue { get; set; }
			[DispId(-2147417065)]
			IHTMLDOMNode parentNode { get; }
			[DispId(-2147417034)]
			IHTMLDOMNode previousSibling { get; }

			[DispId(-2147417039)]
			IHTMLDOMNode appendChild(IHTMLDOMNode newChild);
			[DispId(-2147417051)]
			IHTMLDOMNode cloneNode(bool fDeep);
			[DispId(-2147417064)]
			bool hasChildNodes();
			[DispId(-2147417061)]
			IHTMLDOMNode insertBefore(IHTMLDOMNode newChild, object refChild);
			[DispId(-2147417060)]
			IHTMLDOMNode removeChild(IHTMLDOMNode oldChild);
			[DispId(-2147417046)]
			IHTMLDOMNode removeNode(bool fDeep);
			[DispId(-2147417059)]
			IHTMLDOMNode replaceChild(IHTMLDOMNode newChild, IHTMLDOMNode oldChild);
			[DispId(-2147417045)]
			IHTMLDOMNode replaceNode(IHTMLDOMNode replacement);
			[DispId(-2147417044)]
			IHTMLDOMNode swapNode(IHTMLDOMNode otherNode);
		}

		#endregion

		#region mshtml class

		[ComImport]
		[Guid("3050F38D-98B5-11CF-BB82-00AA00BDCE0B")]
		[ClassInterface((short)0)]
		[DefaultMember("create")]
		[TypeLibType((short)2)]
		class HTMLOptionElementFactoryClass// : IHTMLOptionElementFactory, HTMLOptionElementFactory
		{
		}

		[ComImport]
		[ClassInterface((short)0)]
		[Guid("3050F38F-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType((short)2)]
		[DefaultMember("create")]
		class HTMLImageElementFactoryClass// : IHTMLImageElementFactory, HTMLImageElementFactory
		{
		}

		[ComImport]
		[ClassInterface((short)0)]
		[TypeLibType((short)2)]
		[Guid("FECEAAA3-8405-11CF-8BA1-00AA00476DA6")]
		class HTMLHistoryClass// : IOmHistory, HTMLHistory
		{
		}

		[ComImport]
		[ClassInterface((short)0)]
		[TypeLibType((short)2)]
		[Guid("3050F3FE-98B5-11CF-BB82-00AA00BDCE0B")]
		class CMimeTypesClass// : IHTMLMimeTypesCollection, CMimeTypes
		{
		}

		[ComImport]
		[TypeLibType((short)2)]
		[Guid("3050F402-98B5-11CF-BB82-00AA00BDCE0B")]
		[ClassInterface((short)0)]
		class COpsProfileClass// : IHTMLOpsProfile, COpsProfile
		{
		}

		[ComImport, TypeLibType((short)2)]
		[ClassInterface((short)0)]
		[Guid("3050F3FF-98B5-11CF-BB82-00AA00BDCE0B")]
		class CPluginsClass// : IHTMLPluginsCollection, CPlugins
		{
		}

		[ComImport]
		[ClassInterface((short)0)]
		[Guid("FECEAAA6-8405-11CF-8BA1-00AA00476DA6")]
		[TypeLibType((short)2)]
		class HTMLNavigatorClass// : IOmNavigator, HTMLNavigator
		{
		}

		[ComImport, TypeLibType((short)2)]
		[ClassInterface((short)0)]
		[Guid("3050F3CE-98B5-11CF-BB82-00AA00BDCE0B")]
		class HTMLStyleSheetRuleClass// : IHTMLStyleSheetRule, HTMLStyleSheetRule
		{
		}

		[ComImport, DefaultMember("item")]
		[ClassInterface((short)0)]
		[Guid("3050F3CD-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType((short)2)]
		class HTMLStyleSheetRulesCollectionClass// : IHTMLStyleSheetRulesCollection, HTMLStyleSheetRulesCollection
		{
		}

		[ComImport]
		[Guid("3050F37F-98B5-11CF-BB82-00AA00BDCE0B")]
		[ClassInterface((short)0)]
		[DefaultMember("item")]
		[TypeLibType((short)2)]
		class HTMLStyleSheetsCollectionClass// : IHTMLStyleSheetsCollection, HTMLStyleSheetsCollection, IEnumerable
		{
		}

		[ComImport]
		[DefaultMember("href")]
		[Guid("163BB1E1-6E00-11CF-837A-48DC04C10000")]
		[TypeLibType((short)2)]
		[ClassInterface((short)0)]
		class HTMLLocationClass// : IHTMLLocation, HTMLLocation
		{
		}

		[ComImport, DefaultMember("item")]
		[Guid("3050F7F6-98B5-11CF-BB82-00AA00BDCE0B")]
		[TypeLibType((short)2)]
		[ClassInterface((short)0)]
		class FramesCollectionClass// : IHTMLFramesCollection2, FramesCollection
		{
		}

		#endregion

		#region MimeFilter

		public class HRESULT
		{
			public static UInt32 S_OK = 0;
			public static UInt32 S_FALSE = 1;
			public static UInt32 INET_E_DEFAULT_ACTION = 0x800C0011;
		}

		public enum PARSEACTION
		{
			PARSE_CANONICALIZE = 1,
			PARSE_FRIENDLY = PARSE_CANONICALIZE + 1,
			PARSE_SECURITY_URL = PARSE_FRIENDLY + 1,
			PARSE_ROOTDOCUMENT = PARSE_SECURITY_URL + 1,
			PARSE_DOCUMENT = PARSE_ROOTDOCUMENT + 1,
			PARSE_ANCHOR = PARSE_DOCUMENT + 1,
			PARSE_ENCODE = PARSE_ANCHOR + 1,
			PARSE_DECODE = PARSE_ENCODE + 1,
			PARSE_PATH_FROM_URL = PARSE_DECODE + 1,
			PARSE_URL_FROM_PATH = PARSE_PATH_FROM_URL + 1,
			PARSE_MIME = PARSE_URL_FROM_PATH + 1,
			PARSE_SERVER = PARSE_MIME + 1,
			PARSE_SCHEMA = PARSE_SERVER + 1,
			PARSE_SITE = PARSE_SCHEMA + 1,
			PARSE_DOMAIN = PARSE_SITE + 1,
			PARSE_LOCATION = PARSE_DOMAIN + 1,
			PARSE_SECURITY_DOMAIN = PARSE_LOCATION + 1,
			PARSE_ESCAPE = PARSE_SECURITY_DOMAIN + 1,
			PARSE_UNESCAPE = PARSE_ESCAPE + 1,
		}

		public enum QUERYOPTION
		{
			QUERY_EXPIRATION_DATE = 1,
			QUERY_TIME_OF_LAST_CHANGE = QUERY_EXPIRATION_DATE + 1,
			QUERY_CONTENT_ENCODING = QUERY_TIME_OF_LAST_CHANGE + 1,
			QUERY_CONTENT_TYPE = QUERY_CONTENT_ENCODING + 1,
			QUERY_REFRESH = QUERY_CONTENT_TYPE + 1,
			QUERY_RECOMBINE = QUERY_REFRESH + 1,
			QUERY_CAN_NAVIGATE = QUERY_RECOMBINE + 1,
			QUERY_USES_NETWORK = QUERY_CAN_NAVIGATE + 1,
			QUERY_IS_CACHED = QUERY_USES_NETWORK + 1,
			QUERY_IS_INSTALLEDENTRY = QUERY_IS_CACHED + 1,
			QUERY_IS_CACHED_OR_MAPPED = QUERY_IS_INSTALLEDENTRY + 1,
			QUERY_USES_CACHE = QUERY_IS_CACHED_OR_MAPPED + 1,
			QUERY_IS_SECURE = QUERY_USES_CACHE + 1,
			QUERY_IS_SAFE = QUERY_IS_SECURE + 1,
		}


		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("79eac9ec-baf9-11ce-8c82-00aa004ba90b")]
		public interface IInternetProtocolInfo
		{
			[PreserveSig()]
			UInt32 ParseUrl(
				[MarshalAs(UnmanagedType.LPWStr)] string pwzUrl,
				/* [in] */ PARSEACTION ParseAction,
				   UInt32 dwParseFlags,
				   IntPtr pwzResult,
				   UInt32 cchResult,
				   out UInt32 pcchResult,
				   UInt32 dwReserved);

			[PreserveSig()]
			UInt32 CombineUrl(
				[MarshalAs(UnmanagedType.LPWStr)] string pwzBaseUrl,
			   [MarshalAs(UnmanagedType.LPWStr)] string pwzRelativeUrl,
			  UInt32 dwCombineFlags,
			  IntPtr pwzResult,
			  UInt32 cchResult,
			  out UInt32 pcchResult,
			  UInt32 dwReserved);

			[PreserveSig()]
			UInt32 CompareUrl(
				[MarshalAs(UnmanagedType.LPWStr)] string pwzUrl1,
			   [MarshalAs(UnmanagedType.LPWStr)] string pwzUrl2,
			  UInt32 dwCompareFlags);

			[PreserveSig()]
			UInt32 QueryInfo(
				[MarshalAs(UnmanagedType.LPWStr)] string pwzUrl,
			   QUERYOPTION OueryOption,
			   UInt32 dwQueryFlags,
			   IntPtr pBuffer,
			   UInt32 cbBuffer,
			   ref UInt32 pcbBuf,
			   UInt32 dwReserved);
		}


		[ComImport]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("79eac9e7-baf9-11ce-8c82-00aa004ba90b")]
		public interface IInternetSession
		{
			void CreateBinding(); // Not Implemented
			void GetCache(); // Not Implemented
			void GetSessionOption(); // Not Implemented
			void RegisterMimeFilter([MarshalAs(UnmanagedType.Interface)] IClassFactory pCF, ref Guid rclsid, [MarshalAs(UnmanagedType.LPWStr)] string pwzType);
			void RegisterNameSpace([MarshalAs(UnmanagedType.Interface)] IClassFactory pCF, ref Guid rclsid, [MarshalAs(UnmanagedType.LPWStr)] string pwzProtocol,
								   UInt32 cPatterns, [MarshalAs(UnmanagedType.LPWStr)] string ppwzPatterns, UInt32 dwReserved);
			void SetCache(); // Not Implemented
			void SetSessionOption(); // Not Implemented
			void UnregisterMimeFilter(IClassFactory pCF, [MarshalAs(UnmanagedType.LPWStr)] string pwzType);
			void UnregisterNameSpace(IClassFactory pCF, [MarshalAs(UnmanagedType.LPWStr)] string pwzProtocol);
		}


		[ComImport]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("79EAC9E5-BAF9-11CE-8C82-00AA004BA90B")]
		public interface IInternetProtocolSink
		{
			void Switch(IntPtr pProtocolData);
			void ReportProgress(UInt32 ulStatusCode, [MarshalAs(UnmanagedType.LPWStr)] string szStatusText);
			void ReportData(UInt32 grfBSCF, UInt32 ulProgress, UInt32 ulProgressMax);
			void ReportResult(Int32 hrResult, UInt32 dwError, [MarshalAs(UnmanagedType.LPWStr)] string szResult);
		}

		[ComImport]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("79EAC9E4-BAF9-11CE-8C82-00AA004BA90B")]
		public interface IInternetProtocol : IInternetProtocolRoot
		{
			void LockRequest(Int32 dwOptions);
			[PreserveSig]
			Int32 Read(IntPtr pv, UInt32 cb, out UInt32 pcbRead);
			void Seek(Int64 dlibMove, UInt32 dwOrigin, out UInt64 plibNewPosition);
			void UnlockRequest();
		}

		[ComImport]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("79EAC9E3-BAF9-11CE-8C82-00AA004BA90B")]
		public interface IInternetProtocolRoot
		{
			void Abort(Int32 hrReason, Int32 dwOptions);
			void Continue(IntPtr pProtocolData);
			void Resume();
			void Start([MarshalAs(UnmanagedType.LPWStr)] string szUrl, IInternetProtocolSink pOIProtSink,
					   IntPtr pOIBindInfo, UInt32 grfPI, IntPtr dwReserved);
			void Suspend();
			void Terminate(Int32 dwOptions);
		}


		[Guid("EFA14C17-7854-4fe2-AF94-856A9714A7B7")]
		public interface IMhtHandler : IInternetProtocol, IInternetProtocolRoot, IInternetProtocolInfo
		{

		}

		[Guid("B59A934A-A06D-4fa1-9AD3-49AEA12235A4"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
		public interface IMhtHandler_Events
		{

		}


		public enum PI_FLAGS : uint
		{
			PI_PARSE_URL = 0x00000001,
			PI_FILTER_MODE = 0x00000002,
			PI_FORCE_ASYNC = 0x00000004,
			PI_USE_WORKERTHREAD = 0x00000008,
			PI_MIMEVERIFICATION = 0x00000010,
			PI_CLSIDLOOKUP = 0x00000020,
			PI_DATAPROGRESS = 0x00000040,
			PI_SYNCHRONOUS = 0x00000080,
			PI_APARTMENTTHREADED = 0x00000100,
			PI_CLASSINSTALL = 0x00000200,
			PI_PASSONBINDCTX = 0x00002000,
			PI_NOMIMEHANDLER = 0x00008000,
			PI_LOADAPPDIRECT = 0x00004000,
			PD_FORCE_SWITCH = 0x00010000,
			PI_PREFERDEFAULTHANDLER = 0x00020000
		}


		public enum BSCF : uint
		{
			BSCF_FIRSTDATANOTIFICATION = 0,
			BSCF_INTERMEDIATEDATANOTIFICATION = 1,
			BSCF_LASTDATANOTIFICATION = 2,
			BSCF_DATAFULLYAVAILABLE = 3,
			BSCF_AVAILABLEDATASIZEUNKNOWN = 4,
		}

		[ComImport]
		[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
		[Guid("00000001-0000-0000-C000-000000000046")]
		public interface IClassFactory
		{
			void CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject);
			void LockServer(bool fLock);
		}

		[ComVisible(true)]
		public class ClassFactory : IClassFactory
		{
			private object _Protocol;

			public ClassFactory() : this(null) { }
			public ClassFactory(object protocol)
			{
				this._Protocol = protocol;
			}

			public void CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)
			{
				ppvObject = Marshal.GetComInterfaceForObject(this._Protocol, typeof(IInternetProtocolInfo));
			}

			public void LockServer(bool fLock)
			{
				//throw new NotImplementedException();
			}
		}

		public class MhtHandler : IMhtHandler
		{
			public const string ProcotolName = "MhtHandler";

			private const int S_OK = 0x00000000;
			private const int S_FALSE = 0x00000001;
			private const int E_FAIL = unchecked((int)0x80004005);
			private const int E_POINTER = unchecked((int)0x80004005);
			private const int INET_E_ERROR_FIRST = unchecked((int)0x800C0002);
			private const int INET_E_INVALID_URL = unchecked((int)0x800C0002);
			//private const int INET_E_INVALID_REQUEST = unchecked((int)0x800C000C);
			private const int INET_E_NO_SESSION = unchecked((int)0x800C0003);
			private const int INET_E_CANNOT_CONNECT = unchecked((int)0x800C0004);
			private const int INET_E_RESOURCE_NOT_FOUND = unchecked((int)0x800C0005);
			private const int INET_E_OBJECT_NOT_FOUND = unchecked((int)0x800C0006);
			private const int INET_E_DATA_NOT_AVAILABLE = unchecked((int)0x800C0007);
			private const int INET_E_DOWNLOAD_FAILURE = unchecked((int)0x800C0008);
			private const int INET_E_AUTHENTICATION_REQUIRED = unchecked((int)0x800C0009);
			private const int INET_E_NO_VALID_MEDIA = unchecked((int)0x800C000A);
			private const int INET_E_CONNECTION_TIMEOUT = unchecked((int)0x800C000B);
			private const int INET_E_INVALID_REQUEST = unchecked((int)0x800C000C);
			private const int INET_E_UNKNOWN_PROTOCOL = unchecked((int)0x800C000D);
			private const int INET_E_SECURITY_PROBLEM = unchecked((int)0x800C000E);
			private const int INET_E_CANNOT_LOAD_DATA = unchecked((int)0x800C000F);
			private const int INET_E_CANNOT_INSTANTIATE_OBJECT = unchecked((int)0x800C0010);
			private const int INET_E_USE_DEFAULT_PROTOCOLHANDLER = unchecked((int)0x800C0011);
			private const int INET_E_QUERYOPTION_UNKNOWN = unchecked((int)0x800C0013);
			private const int INET_E_REDIRECT_FAILED = unchecked((int)0x800C0014);
			private const int INET_E_REDIRECT_TO_DIR = unchecked((int)0x800C0015);
			private const int INET_E_CANNOT_LOCK_REQUEST = unchecked((int)0x800C0016);

			private const uint BINDSTATUS_FINDINGRESOURCE = 1;
			private const uint BINDSTATUS_CONNECTING = BINDSTATUS_FINDINGRESOURCE + 1;
			private const uint BINDSTATUS_REDIRECTING = BINDSTATUS_CONNECTING + 1;
			private const uint BINDSTATUS_BEGINDOWNLOADDATA = BINDSTATUS_REDIRECTING + 1;
			private const uint BINDSTATUS_DOWNLOADINGDATA = BINDSTATUS_BEGINDOWNLOADDATA + 1;
			private const uint BINDSTATUS_ENDDOWNLOADDATA = BINDSTATUS_DOWNLOADINGDATA + 1;
			private const uint BINDSTATUS_BEGINDOWNLOADCOMPONENTS = BINDSTATUS_ENDDOWNLOADDATA + 1;
			private const uint BINDSTATUS_INSTALLINGCOMPONENTS = BINDSTATUS_BEGINDOWNLOADCOMPONENTS + 1;
			private const uint BINDSTATUS_ENDDOWNLOADCOMPONENTS = BINDSTATUS_INSTALLINGCOMPONENTS + 1;
			private const uint BINDSTATUS_USINGCACHEDCOPY = BINDSTATUS_ENDDOWNLOADCOMPONENTS + 1;
			private const uint BINDSTATUS_SENDINGREQUEST = BINDSTATUS_USINGCACHEDCOPY + 1;
			private const uint BINDSTATUS_CLASSIDAVAILABLE = BINDSTATUS_SENDINGREQUEST + 1;
			private const uint BINDSTATUS_MIMETYPEAVAILABLE = BINDSTATUS_CLASSIDAVAILABLE + 1;
			private const uint BINDSTATUS_CACHEFILENAMEAVAILABLE = BINDSTATUS_MIMETYPEAVAILABLE + 1;

			public static byte[] buffer = new byte[0];
			public static uint pos = 0;
			public IInternetProtocolSink ProtSink;

			#region IInternetProtocol 成员

			public void LockRequest(int dwOptions)
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, S_OK);
			}

			public int Read(IntPtr pv, uint cb, out uint pcbRead)
			{
				//throw new NotImplementedException();
				if ((buffer.Length - pos) <= cb)
				{
					Marshal.Copy(buffer, (int)pos, pv, (int)(buffer.Length - pos));
					pcbRead = (uint)(buffer.Length - pos);
					pos = 0;
					ProtSink.ReportResult(S_OK, 0, null);
					return S_FALSE;
				}
				else
				{
					Marshal.Copy(buffer, (int)pos, pv, (int)cb);
					pos += cb;
					pcbRead = cb;
					return S_OK;
				}
			}

			public void Seek(long dlibMove, uint dwOrigin, out ulong plibNewPosition)
			{
				//throw new NotImplementedException();
				plibNewPosition = new ulong();
				throw new COMException(string.Empty, E_FAIL);
			}

			public void UnlockRequest()
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, S_OK);
			}

			#endregion

			#region IInternetProtocolRoot 成员

			public void Abort(int hrReason, int dwOptions)
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, INET_E_INVALID_REQUEST);
			}

			public void Continue(IntPtr pProtocolData)
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, INET_E_INVALID_REQUEST);
			}

			public void Resume()
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, INET_E_INVALID_REQUEST);
			}

			public void Start([MarshalAs(UnmanagedType.LPWStr)] string szUrl, IInternetProtocolSink pOIProtSink, IntPtr pOIBindInfo, uint grfPI, IntPtr dwReserved)
			{
				//throw new NotImplementedException();
				if ((grfPI & 0x00000001) != 0)
					throw new COMException(string.Empty, S_OK);

				if (pOIProtSink == null)
					throw new COMException(string.Empty, E_POINTER);

				ProtSink = pOIProtSink;
				pOIProtSink.ReportData(2, 0, (uint)buffer.Length);
				pOIProtSink.ReportData(3, 0, (uint)buffer.Length);
				throw new COMException(string.Empty, S_OK);
			}

			public void Suspend()
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, INET_E_INVALID_REQUEST);
			}

			public void Terminate(int dwOptions)
			{
				//throw new NotImplementedException();
				throw new COMException(string.Empty, S_OK);
			}

			#endregion

			#region IInternetProtocolInfo 成员

			string DirectoryFromBaseUrl(string Url)
			{
				int loc = Url.LastIndexOf('/');
				if (loc < 0)
					return String.Empty;

				return Url.Substring(0, loc + 1);
			}

			string VirtualDirctoryFromBaseUrl(string Url)
			{
				int loc = Url.LastIndexOf('/');
				if (loc < 0)
					return String.Empty;

				return Url.Substring(0, loc);
			}

			public uint ParseUrl(string pwzUrl, PARSEACTION ParseAction, uint dwParseFlags, IntPtr pwzResult, uint cchResult, out uint pcchResult, uint dwReserved)
			{
				//throw new NotImplementedException();
				pcchResult = 0;
				return HRESULT.INET_E_DEFAULT_ACTION;
			}

			public uint CombineUrl(string pwzBaseUrl, string pwzRelativeUrl, uint dwCombineFlags, IntPtr pwzResult, uint cchResult, out uint pcchResult, uint dwReserved)
			{
				//throw new NotImplementedException();
				string temp = null;
				if (pwzRelativeUrl.Substring(0, 1) != "/")
					temp = DirectoryFromBaseUrl(pwzBaseUrl) + pwzRelativeUrl;
				else
					temp = VirtualDirctoryFromBaseUrl(pwzBaseUrl) + pwzRelativeUrl;
				if (pwzRelativeUrl.IndexOf(":") > 0)
					temp = pwzRelativeUrl;
				if (temp.Length > cchResult)
				{
					pcchResult = 0;
					return HRESULT.S_FALSE;
				}

				//Marshal.Copy(temp.ToCharArray(), 0, pwzBuffer, temp.Length);
				//Marshal.WriteInt32(pwzBuffer, temp.Length * 2, 0);
				pcchResult = (UInt32)temp.Length + 1;
				return HRESULT.S_OK;
			}

			public uint CompareUrl(string pwzUrl1, string pwzUrl2, uint dwCompareFlags)
			{
				//throw new NotImplementedException();
				return (UInt32)pwzUrl1.CompareTo(pwzUrl2);
			}

			public uint QueryInfo(string pwzUrl, QUERYOPTION OueryOption, uint dwQueryFlags, IntPtr pBuffer, uint cbBuffer, ref uint pcbBuf, uint dwReserved)
			{
				//throw new NotImplementedException();
				return HRESULT.INET_E_DEFAULT_ACTION;
			}

			#endregion
		}

		#endregion

		#region const

		private const int SET_FEATURE_ON_THREAD = 0x00000001;
		private const int SET_FEATURE_ON_PROCESS = 0x00000002;
		private const int SET_FEATURE_IN_REGISTRY = 0x00000004;
		private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
		private const int SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
		private const int SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
		private const int SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
		private const int SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;

		#endregion

		private static Guid ViewObject = new Guid("{0000010d-0000-0000-C000-000000000046}");//IViewObject class interface

		#region Event Key s

		private static readonly object StatusTextChangeHandlerKey = new object();
		private static readonly object ProgressChangeHandlerKey = new object();
		private static readonly object CommandStateChangeHandlerKey = new object();
		private static readonly object DownloadBeginHandlerKey = new object();
		private static readonly object DownloadCompleteHandlerKey = new object();
		private static readonly object TitleChangeHandlerKey = new object();
		private static readonly object PropertyChangeHandlerKey = new object();
		private static readonly object BeforeNavigateHandlerKey = new object();
		private static readonly object NewWindow2HandlerKey = new object();
		private static readonly object NavigateCompleteHandlerKey = new object();
		private static readonly object DocumentCompleteHandlerKey = new object();
		private static readonly object QuitHandlerKey = new object();
		private static readonly object VisibleHandlerKey = new object();
		private static readonly object ToolBarHandlerKey = new object();
		private static readonly object MenuBarHandlerKey = new object();
		private static readonly object StatusBarHandlerKey = new object();
		private static readonly object FullScreenHandlerKey = new object();
		private static readonly object TheaterModeHandlerKey = new object();
		private static readonly object SetResizableHandlerKey = new object();
		private static readonly object SetLeftHandlerKey = new object();
		private static readonly object SetTopHandlerKey = new object();
		private static readonly object SetWidthHandlerKey = new object();
		private static readonly object SetHeightHandlerKey = new object();
		private static readonly object ClosingHandlerKey = new object();
		private static readonly object ClientToHostWindowHandlerKey = new object();
		private static readonly object SetSecureLockIconHandlerKey = new object();
		private static readonly object DownloadFileHandlerKey = new object();
		private static readonly object NavigateErrorHandlerKey = new object();
		private static readonly object PrintTemplateInstantiationHandlerKey = new object();
		private static readonly object PrintTemplateTeardownHandlerKey = new object();
		private static readonly object UpdatePageStatusHandlerKey = new object();
		private static readonly object PrivacyImpactedStateChangeHandlerKey = new object();
		private static readonly object BeforeNewWindowHandlerKey = new object();

		#endregion

		private bool _RegisterAsBrowser = true;
		private bool _Silent = true;

		private IWebBrowser _WebBrowser;
		private IWebBrowser2 _WebBrowser2;
		private IWebBrowserApp _WebBrowserApp;
		private AxHost.ConnectionPointCookie _ConnectionPointCookie_DWebBrowserEvents2;

		#region Events

		/// <summary>
		/// 状态栏文字改变时发生的事件。
		/// </summary>
		public event UrlNavigateHandler StatusTextChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.StatusTextChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.StatusTextChangeHandlerKey, value);
			}
		}

		public event UrlNavigateHandler ProgressChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.ProgressChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.ProgressChangeHandlerKey, value);
			}
		}

		public event UrlNavigateHandler CommandStateChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.CommandStateChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.CommandStateChangeHandlerKey, value);
			}
		}

		public event EventHandler DownloadBegin
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.DownloadBeginHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.DownloadBeginHandlerKey, value);
			}
		}

		public event EventHandler DownloadComplete
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.DownloadCompleteHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.DownloadCompleteHandlerKey, value);
			}
		}

		public event UrlNavigateHandler TitleChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.TitleChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.TitleChangeHandlerKey, value);
			}
		}

		public event PropertyChangedEventHandler PropertyChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.PropertyChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.PropertyChangeHandlerKey, value);
			}
		}

		/// <summary>
		/// 在导航前发生的事件
		/// </summary>
		public event UrlNavigateHandler BeforeNavigate
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.BeforeNavigateHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.BeforeNavigateHandlerKey, value);
			}
		}

		public event UrlNavigateHandler NewWindow2
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.NewWindow2HandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.NewWindow2HandlerKey, value);
			}
		}

		public event UrlNavigateHandler NavigateComplete
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.NavigateCompleteHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.NavigateCompleteHandlerKey, value);
			}
		}

		public event UrlNavigateHandler DocumentComplete
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.DocumentCompleteHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.DocumentCompleteHandlerKey, value);
			}
		}

		public event EventHandler Quit
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.QuitHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.QuitHandlerKey, value);
			}
		}

		public event UrlNavigateHandler Display
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.VisibleHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.VisibleHandlerKey, value);
			}
		}

		public event UrlNavigateHandler ToolBar
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.ToolBarHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.ToolBarHandlerKey, value);
			}
		}

		public event UrlNavigateHandler MenuBar
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.MenuBarHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.MenuBarHandlerKey, value);
			}
		}

		public event UrlNavigateHandler StatusBar
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.StatusBarHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.StatusBarHandlerKey, value);
			}
		}

		public event UrlNavigateHandler FullScreen
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.FullScreenHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.FullScreenHandlerKey, value);
			}
		}

		public event UrlNavigateHandler TheaterMode
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.TheaterModeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.TheaterModeHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetResizable
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetResizableHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetResizableHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetLeft
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetLeftHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetLeftHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetTop
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetTopHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetTopHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetWidth
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetWidthHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetWidthHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetHeight
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetHeightHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetHeightHandlerKey, value);
			}
		}

		public event UrlNavigateHandler Closing
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.ClosingHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.ClosingHandlerKey, value);
			}
		}

		public event UrlNavigateHandler ClientToHostWindow
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.ClientToHostWindowHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.ClientToHostWindowHandlerKey, value);
			}
		}

		public event UrlNavigateHandler SetSecureLockIcon
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.SetSecureLockIconHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.SetSecureLockIconHandlerKey, value);
			}
		}

		public event CancelEventHandler DownloadFile
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.DownloadFileHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.DownloadFileHandlerKey, value);
			}
		}

		/// <summary>
		/// 在导航出错时发生的事件
		/// </summary>
		public event UrlNavigateHandler NavigateError
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.NavigateErrorHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.NavigateErrorHandlerKey, value);
			}
		}

		public event UrlNavigateHandler PrintTemplateInstantiation
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.PrintTemplateInstantiationHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.PrintTemplateInstantiationHandlerKey, value);
			}
		}

		public event UrlNavigateHandler PrintTemplateTeardown
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.PrintTemplateTeardownHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.PrintTemplateTeardownHandlerKey, value);
			}
		}

		public event UrlNavigateHandler UpdatePageStatus
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.UpdatePageStatusHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.UpdatePageStatusHandlerKey, value);
			}
		}

		public event UrlNavigateHandler PrivacyImpactedStateChange
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.PrivacyImpactedStateChangeHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.PrivacyImpactedStateChangeHandlerKey, value);
			}
		}

		/// <summary>
		/// 在需要打开新窗口前发生的事件
		/// </summary>
		public event UrlNavigateHandler BeforeNewWindow
		{
			add
			{
				this.Events.AddHandler(InternetExplorer.BeforeNewWindowHandlerKey, value);
			}
			remove
			{
				this.Events.RemoveHandler(InternetExplorer.BeforeNewWindowHandlerKey, value);
			}
		}

		#endregion

		/// <summary>
		/// 返回或设置 WebBrowser 是否处于沉默模式。如果处于沉默模式，意味着没有对话框可以被显示.
		/// </summary>
		public bool Silent
		{
			set
			{
				var wb = this.ActiveXInstance as IWebBrowser2;
				//if (wb == null)
				//    throw new AxHost.InvalidActiveXStateException("Silent", AxHost.ActiveXInvokeKind.PropertyGet);

				//wb.Silent = value;
				try
				{
					if (wb != null)
						wb.Silent = value;
				}
				catch { }
				this._Silent = value;
			}
			get
			{
				var wb = this.ActiveXInstance as IWebBrowser2;
				if (wb == null)
					throw new AxHost.InvalidActiveXStateException("Silent", AxHost.ActiveXInvokeKind.PropertyGet);

				return wb.Silent;
			}
		}

		/// <summary>
		/// 设置或者检测Webbrowser是否是作为顶层浏览器被登记
		/// </summary>
		public bool RegisterAsBrowser
		{
			set
			{
				//var wb = this.ActiveXInstance as IWebBrowser2;
				//if (wb == null)
				//    throw new AxHost.InvalidActiveXStateException("RegisterAsBrowser", AxHost.ActiveXInvokeKind.PropertyGet);

				//wb.RegisterAsBrowser = value;
				try
				{
					//if (wb != null)
					//    wb.RegisterAsBrowser = value;
					if (this._WebBrowser2 != null)
						this._WebBrowser2.RegisterAsBrowser = value;
				}
				catch { }
				this._RegisterAsBrowser = true;
			}
			get
			{
				var wb = this.ActiveXInstance as IWebBrowser2;
				if (wb == null)
					throw new AxHost.InvalidActiveXStateException("RegisterAsBrowser", AxHost.ActiveXInvokeKind.PropertyGet);

				return wb.RegisterAsBrowser;
			}
		}

		/// <summary>
		/// 创建基础 ActiveX 控件时由该控件调用。
		/// </summary>
		/// <param name="nativeActiveXObject">表示基础 ActiveX 控件的对象。</param>
		protected override void AttachInterfaces(object nativeActiveXObject)
		{
			base.AttachInterfaces(nativeActiveXObject);
			this._WebBrowser = nativeActiveXObject as IWebBrowser;
			this._WebBrowser2 = nativeActiveXObject as IWebBrowser2;
			this._WebBrowserApp = nativeActiveXObject as IWebBrowserApp;
		}

		/// <summary>
		/// 放弃基础 ActiveX 控件时由该控件调用。
		/// </summary>
		protected override void DetachInterfaces()
		{
			base.DetachInterfaces();
			this._WebBrowser = null;
			this._WebBrowser2 = null;
			this._WebBrowserApp = null;
		}

		/// <summary>
		/// 使基础 ActiveX 控件与可以处理控件事件的客户端相关联。
		/// </summary>
		protected override void CreateSink()
		{
			base.CreateSink();
			//var wb = this.ActiveXInstance as IWebBrowser2;
			//if (wb != null)
			//{
			//    wb.Silent = this._Silent;
			//    wb.RegisterAsBrowser = this._RegisterAsBrowser;
			//}
			if (this._WebBrowser2 != null)
			{
				this._WebBrowser2.Silent = this._Silent;
				this._WebBrowser2.RegisterAsBrowser = this._RegisterAsBrowser;
			}
			this._ConnectionPointCookie_DWebBrowserEvents2 = new AxHost.ConnectionPointCookie(this.ActiveXInstance, new DWebBrowserEvents2Class(this), typeof(DWebBrowserEvents2));
		}

		/// <summary>
		/// 从基础 ActiveX 控件中释放附加在 System.Windows.Forms.WebBrowser.CreateSink() 方法中的事件处理客户端。
		/// </summary>
		protected override void DetachSink()
		{

			if (this._ConnectionPointCookie_DWebBrowserEvents2 != null)
			{
				this._ConnectionPointCookie_DWebBrowserEvents2.Disconnect();
				this._ConnectionPointCookie_DWebBrowserEvents2 = null;
			}
			base.DetachSink();
		}

		#region Events On

		/// <summary>
		/// 引发 StatusTextChange 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnStatusTextChange(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.StatusTextChangeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		/// <summary>
		/// 引发 ProgressChange 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnProgressChange(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.ProgressChangeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		/// <summary>
		/// 引发 CommandStateChange 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnCommandStateChange(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.CommandStateChangeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnDownloadBegin(EventArgs e)
		{
			var h = this.Events[InternetExplorer.DownloadBeginHandlerKey] as EventHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnDownloadComplete(EventArgs e)
		{
			var h = this.Events[InternetExplorer.DownloadCompleteHandlerKey] as EventHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnTitleChange(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.TitleChangeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnPropertyChange(PropertyChangedEventArgs e)
		{
			var h = this.Events[InternetExplorer.PropertyChangeHandlerKey] as PropertyChangedEventHandler;
			if (h != null)
				h(this, e);
		}

		/// <summary>
		/// 引发 BeforeNavigate 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnBeforeNavigate(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.BeforeNavigateHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnNewWindow2(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.NewWindow2HandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnNavigateComplete(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.NavigateCompleteHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnDocumentComplete(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.DocumentCompleteHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnQuit(EventArgs e)
		{
			var h = this.Events[InternetExplorer.QuitHandlerKey] as EventHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnDisplay(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.VisibleHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnToolBar(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.ToolBarHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnMenuBar(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.MenuBarHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnStatusBar(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.StatusBarHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnFullScreen(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.FullScreenHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnTheaterMode(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.TheaterModeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetResizable(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetResizableHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetLeft(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetLeftHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetTop(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetTopHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetWidth(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetWidthHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetHeight(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetHeightHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnClosing(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.ClosingHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnClientToHostWindow(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.ClientToHostWindowHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnSetSecureLockIcon(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.SetSecureLockIconHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnDownloadFile(CancelEventArgs e)
		{
			var h = this.Events[InternetExplorer.DownloadFileHandlerKey] as CancelEventHandler;
			if (h != null)
				h(this, e);
		}

		/// <summary>
		/// 引发 NavigateError 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnNavigateError(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.NavigateErrorHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnPrintTemplateInstantiation(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.PrintTemplateInstantiationHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnPrintTemplateTeardown(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.PrintTemplateTeardownHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnUpdatePageStatus(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.UpdatePageStatusHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		protected virtual void OnPrivacyImpactedStateChange(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.PrivacyImpactedStateChangeHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		/// <summary>
		/// 引发 BeforeNewWindow 事件
		/// </summary>
		/// <param name="e">事件参数</param>
		protected virtual void OnBeforeNewWindow(UrlNavigateEventArgs e)
		{
			var h = this.Events[InternetExplorer.BeforeNewWindowHandlerKey] as UrlNavigateHandler;
			if (h != null)
				h(this, e);
		}

		#endregion

		private static void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds, object activeXInstance)
		{
			if (activeXInstance == null)
				return;

			if (!Marshal.IsComObject(activeXInstance))
				return;

			var h = IntPtr.Zero;
			var g = Graphics.FromImage(bitmap);
			Marshal.QueryInterface(Marshal.GetIUnknownForObject(activeXInstance), ref ViewObject, out h);
			try
			{
				activeXInstance = Marshal.GetTypedObjectForIUnknown(h, typeof(IViewObject));
				var viewObject = activeXInstance as IViewObject;
				viewObject.Draw(1, -1, IntPtr.Zero, null, IntPtr.Zero, g.GetHdc(), new COMRECT(targetBounds), null, IntPtr.Zero, 0);
				Marshal.Release(h);
			}
			catch (Exception x)
			{
				Tracker.WriteError(x);
				Debug.Write(x);
				throw;
			}

			g.Dispose();
		}

		/// <summary>
		/// 支持呈现到指定的位图。
		/// </summary>
		/// <param name="bitmap">要绘制到的位图。</param>
		/// <param name="targetBounds">呈现控件时的边界。</param>
		public new void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds)
		{
			//(this as Control).DrawToBitmap(bitmap, targetBounds);
			//base.DrawToBitmap(bitmap, targetBounds);
			InternetExplorer.DrawToBitmap(bitmap, targetBounds, this.ActiveXInstance);
		}

		/// <summary/>
		public void ExecWB(int cmdID, int cmdexecopt, ref object pvaIn, IntPtr pvaOut)
		{
			this._WebBrowser2.ExecWB((OLECMDID)cmdID, (OLECMDEXECOPT)cmdexecopt, ref pvaIn, IntPtr.Zero);
		}

		/// <summary/>
		public void ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, ref object pvaIn, IntPtr pvaOut)
		{
			this._WebBrowser2.ExecWB(cmdID, cmdexecopt, ref pvaIn, IntPtr.Zero);
		}

		/// <summary>
		/// 返回跨域非安全的 Frame 内容
		/// </summary>
		/// <param name="frame">frame:mshtml.HTMLWindow2</param>
		/// <returns>跨域非安全的 SHDocVw.WebBrowser 对象</returns>
		public object GetUnsafeFrame(object frame)
		{
			return this.GetUnsafeFrame(frame, null);
		}
		/// <summary>
		/// 返回跨域非安全的 Frame 内容
		/// </summary>
		/// <param name="frame">frame:mshtml.HTMLWindow2</param>
		/// <param name="type">SHDocVw.WebBrowserClass</param>
		/// <returns>跨域非安全的 SHDocVw.WebBrowser 对象</returns>
		public object GetUnsafeFrame(object frame, Type type)
		{
			//var window = frame as IHTMLWindow2;
			//if (window == null)
			//    return null;

			var sp = frame as PickGold.Com.IServiceProvider;
			if (sp == null)
				return null;

			var IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
			var IID_IWebBrowserApp = new Guid("{0002DF05-0000-0000-C000-000000000046}");
			var result = sp.QueryService(ref IID_IWebBrowserApp, ref IID_IUnknown, out frame);
			if (result != 0)
				return null;

			if (type == null)
				type = typeof(WebBrowserClass);
			return Marshal.CreateWrapperOfType(frame, type);
			//var wb = pOut as WebBrowser;
			//d2 = wb.Document as IHTMLDocument2;
			//d3 = wb.Document as IHTMLDocument3;
			//return pOut;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sessionMode"></param>
		/// <param name="session"></param>
		/// <param name="reserved"></param>
		[DllImport("urlmon.dll")]
		public static extern void CoInternetGetSession(int sessionMode, out IInternetSession session, int reserved);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="FeatureEntry"></param>
		/// <param name="dwFlags"></param>
		/// <param name="fEnable"></param>
		/// <returns></returns>
		/// <!-- CoInternetSetFeatureEnabled(INTERNETFEATURELIST.FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); -->
		[DllImport("urlmon.dll")]
		[PreserveSig]
		[return: MarshalAs(UnmanagedType.Error)]
		static extern int CoInternetSetFeatureEnabled(INTERNETFEATURELIST FeatureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="protocol"></param>
		public void RegisterMimeFilter(object protocol)
		{
			IInternetSession session = null;
			InternetExplorer.CoInternetGetSession(0, out session, 0);
			var guid = new Guid("79EAC9E4-BAF9-11CE-8C82-00AA004BA90B");
			session.RegisterNameSpace(new ClassFactory(protocol), ref guid, protocol.GetType().FullName, 0, null, 0);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="protocol"></param>
		public void UnRegisterMimeFilter(object protocol)
		{
			IInternetSession session = null;
			InternetExplorer.CoInternetGetSession(0, out session, 0);
			session.UnregisterNameSpace(new ClassFactory(protocol), protocol.GetType().FullName);
		}

		/// <summary>
		/// 返回对非托管 WebBrowser ActiveX 控件站点的引用，扩展该站点可以对托管 System.Windows.Forms.WebBrowser 控件进行自定义。
		/// </summary>
		/// <returns>System.Windows.Forms.WebBrowser.WebBrowserSite，表示 WebBrowser ActiveX 控件站点。</returns>
		//protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
		//{
		//    return base.CreateWebBrowserSiteBase();
		//    return new InternetExplorerSite(this);
		//}

		/// <summary>
		/// 缩放网页
		/// </summary>
		/// <param name="scale">缩放比率</param>
		public void Zoom(int scale)
		{
			object o = scale;
			try
			{
				this._WebBrowser2.ExecWB(OLECMDID.ZOOM, OLECMDEXECOPT.DODEFAULT, ref o, IntPtr.Zero);
			}
			catch// (Exception x)
			{
				o = scale;
				this._WebBrowser2.ExecWB(OLECMDID.OPTICAL_ZOOM, OLECMDEXECOPT.DODEFAULT, ref o, IntPtr.Zero);
			}
		}
	}

	/// <summary>
	/// 为浏览器导航事件提供参数
	/// </summary>
	[Serializable]
	[ComVisible(true)]
	[ClassInterface(ClassInterfaceType.AutoDispatch)]
	public class UrlNavigateEventArgs : CancelEventArgs
	{
		private string _Url;
		private string _Frame;
		private int _StatusCode;
		private object _Data;
		private bool _IsDataReadOnly;

		/// <summary>
		/// 目标地址
		/// </summary>
		public string Url
		{
			get
			{
				return _Url;
			}
		}

		/// <summary>
		/// 目标帧/框架
		/// </summary>
		public string Frame
		{
			get
			{
				return _Frame;
			}
		}

		/// <summary>
		/// 状态代码
		/// </summary>
		public int StatusCode
		{
			get
			{
				return this._StatusCode;
			}
		}

		public object Flags { set; get; }

		public object PostData { set; get; }

		public object Headers { set; get; }

		public object UrlContext { set; get; }

		public object Data
		{
			set
			{
				if (this._IsDataReadOnly)
					throw new NotSupportedException("Read only.");

				this._Data = value;
			}
			get
			{
				return this._Data;
			}
		}

		/// <summary>
		/// 目标浏览器控件
		/// </summary>
		public InternetExplorer Target { set; get; }

		/// <summary>
		/// 构造一个 UrlNavigateEventArgs 对象实例
		/// </summary>
		/// <param name="url">目标地址</param>
		/// <param name="frame">目标帧/框架</param>
		/// <param name="statusCode">状态代码</param>
		public UrlNavigateEventArgs(string url, string frame, int statusCode)
		{
			this._Url = url;
			this._Frame = frame;
			this._StatusCode = statusCode;
		}
		/// <summary>
		/// 构造一个 UrlNavigateEventArgs 对象实例
		/// </summary>
		/// <param name="url">目标地址</param>
		/// <param name="frame">目标帧/框架</param>
		/// <param name="statusCode">状态代码</param>
		/// <param name="data">附加数据</param>
		public UrlNavigateEventArgs(string url, string frame, int statusCode, object data)
		{
			this._Url = url;
			this._Frame = frame;
			this._StatusCode = statusCode;

			this._Data = data;
			this._IsDataReadOnly = true;
		}
	}

	/// <summary>
	/// 表示处理浏览器导航事件的方法
	/// </summary>
	/// <param name="sender">事件源。</param>
	/// <param name="e">包含浏览器导航事件参数的 UrlNavigateEventArgs 对象。</param>
	[ComVisible(true)]
	public delegate void UrlNavigateHandler(object sender, UrlNavigateEventArgs e);
}
/*
procedure TForm1.FormCreate(Sender: TObject);
var
  hDSound: Cardinal;
  pDirectSoundCreate: Pointer;
  hWinmm: Cardinal;
  pmidiStreamOpen: Pointer;
  pwaveOutWrite: Pointer;
  lp: Cardinal;
begin
  hDSound := LoadLibrary('DSound.dll');
  if hDSound > 0 then
    pDirectSoundCreate := GetProcAddress(hDSound, 'DirectSoundCreate');
  if pDirectSoundCreate <> nil then
  begin
    VirtualProtect(pDirectSoundCreate, 3, PAGE_EXECUTE_READWRITE, lp);
    Move(#$C2#$0C#$00, pDirectSoundCreate^, 3);
  end;

  hWinmm := LoadLibrary('Winmm.dll');
  if hWinmm > 0 then
    pmidiStreamOpen := GetProcAddress(hWinmm, 'midiStreamOpen');
  if pmidiStreamOpen <> nil then
  begin
    VirtualProtect(pmidiStreamOpen, 3, PAGE_EXECUTE_READWRITE, lp);
    Move(#$C2#$04#$00, pmidiStreamOpen^, 3);
  end;

  if hWinmm > 0 then
    pwaveOutWrite := GetProcAddress(hWinmm, 'waveOutWrite');
  if pwaveOutWrite <> nil then
  begin
    VirtualProtect(pwaveOutWrite, 3, PAGE_EXECUTE_READWRITE, lp);
    Move(#$C2#$0C#$00, pwaveOutWrite^, 3);
  end;
end;
*/
